1
0

PerformanceTablesCard.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <script setup lang="ts">
  2. import type { NginxPerformanceInfo } from '@/api/ngx'
  3. import type { TableColumnType } from 'ant-design-vue'
  4. import { InfoCircleOutlined } from '@ant-design/icons-vue'
  5. import { computed, defineProps, ref } from 'vue'
  6. const props = defineProps<{
  7. nginxInfo: NginxPerformanceInfo
  8. }>()
  9. const activeTabKey = ref('status')
  10. // Table column definition
  11. const columns: TableColumnType[] = [
  12. {
  13. title: $gettext('Indicator'),
  14. dataIndex: 'name',
  15. key: 'name',
  16. width: '30%',
  17. },
  18. {
  19. title: $gettext('Value'),
  20. dataIndex: 'value',
  21. key: 'value',
  22. },
  23. ]
  24. // Format numbers
  25. function formatNumber(num: number): string {
  26. if (num >= 1000000) {
  27. return `${(num / 1000000).toFixed(2)}M`
  28. }
  29. else if (num >= 1000) {
  30. return `${(num / 1000).toFixed(2)}K`
  31. }
  32. return num.toString()
  33. }
  34. // Status data
  35. const statusData = computed(() => {
  36. return [
  37. {
  38. key: '1',
  39. name: $gettext('Active connections'),
  40. value: formatNumber(props.nginxInfo.active),
  41. },
  42. {
  43. key: '2',
  44. name: $gettext('Total handshakes'),
  45. value: formatNumber(props.nginxInfo.accepts),
  46. },
  47. {
  48. key: '3',
  49. name: $gettext('Total connections'),
  50. value: formatNumber(props.nginxInfo.handled),
  51. },
  52. {
  53. key: '4',
  54. name: $gettext('Total requests'),
  55. value: formatNumber(props.nginxInfo.requests),
  56. },
  57. {
  58. key: '5',
  59. name: $gettext('Read requests'),
  60. value: props.nginxInfo.reading,
  61. },
  62. {
  63. key: '6',
  64. name: $gettext('Responses'),
  65. value: props.nginxInfo.writing,
  66. },
  67. {
  68. key: '7',
  69. name: $gettext('Waiting processes'),
  70. value: props.nginxInfo.waiting,
  71. },
  72. ]
  73. })
  74. // Worker processes data
  75. const workerData = computed(() => {
  76. return [
  77. {
  78. key: '1',
  79. name: $gettext('Number of worker processes'),
  80. value: props.nginxInfo.workers,
  81. },
  82. {
  83. key: '2',
  84. name: $gettext('Master process'),
  85. value: props.nginxInfo.master,
  86. },
  87. {
  88. key: '3',
  89. name: $gettext('Cache manager processes'),
  90. value: props.nginxInfo.cache,
  91. },
  92. {
  93. key: '4',
  94. name: $gettext('Other Nginx processes'),
  95. value: props.nginxInfo.other,
  96. },
  97. {
  98. key: '5',
  99. name: $gettext('Nginx CPU usage rate'),
  100. value: `${props.nginxInfo.cpu_usage.toFixed(2)}%`,
  101. },
  102. {
  103. key: '6',
  104. name: $gettext('Nginx Memory usage'),
  105. value: `${props.nginxInfo.memory_usage.toFixed(2)} MB`,
  106. },
  107. ]
  108. })
  109. // Configuration data
  110. const configData = computed(() => {
  111. return [
  112. {
  113. key: '1',
  114. name: $gettext('Number of worker processes'),
  115. value: props.nginxInfo.worker_processes,
  116. },
  117. {
  118. key: '2',
  119. name: $gettext('Maximum number of connections per worker process'),
  120. value: props.nginxInfo.worker_connections,
  121. },
  122. ]
  123. })
  124. // Maximum requests per second
  125. const maxRPS = computed(() => {
  126. return props.nginxInfo.worker_processes * props.nginxInfo.worker_connections
  127. })
  128. </script>
  129. <template>
  130. <ACard :bordered="false">
  131. <ATabs v-model:active-key="activeTabKey">
  132. <!-- Request statistics -->
  133. <ATabPane key="status" :tab="$gettext('Request statistics')">
  134. <div class="overflow-x-auto">
  135. <ATable
  136. :columns="columns"
  137. :data-source="statusData"
  138. :pagination="false"
  139. size="middle"
  140. :scroll="{ x: '100%' }"
  141. />
  142. </div>
  143. </ATabPane>
  144. <!-- Process information -->
  145. <ATabPane key="workers" :tab="$gettext('Process information')">
  146. <div class="overflow-x-auto">
  147. <ATable
  148. :columns="columns"
  149. :data-source="workerData"
  150. :pagination="false"
  151. size="middle"
  152. :scroll="{ x: '100%' }"
  153. />
  154. </div>
  155. </ATabPane>
  156. <!-- Configuration information -->
  157. <ATabPane key="config" :tab="$gettext('Configuration information')">
  158. <div class="overflow-x-auto">
  159. <ATable
  160. :columns="columns"
  161. :data-source="configData"
  162. :pagination="false"
  163. size="middle"
  164. :scroll="{ x: '100%' }"
  165. />
  166. </div>
  167. <div class="mt-4">
  168. <AAlert type="info" show-icon>
  169. <template #message>
  170. {{ $gettext('Nginx theoretical maximum performance') }}
  171. </template>
  172. <template #description>
  173. <p>
  174. {{ $gettext('Theoretical maximum concurrent connections:') }}
  175. <strong>{{ nginxInfo.worker_processes * nginxInfo.worker_connections }}</strong>
  176. </p>
  177. <p>
  178. {{ $gettext('Theoretical maximum RPS (Requests Per Second):') }}
  179. <strong>{{ maxRPS }}</strong>
  180. <ATooltip :title="$gettext('Calculated based on worker_processes * worker_connections. Actual performance depends on hardware, configuration, and workload')">
  181. <InfoCircleOutlined class="ml-1 text-gray-500" />
  182. </ATooltip>
  183. </p>
  184. <p>
  185. {{ $gettext('Maximum worker process number:') }}
  186. <strong>{{ nginxInfo.worker_processes }}</strong>
  187. <span class="text-gray-500 text-xs ml-2">
  188. {{
  189. nginxInfo.process_mode === 'auto'
  190. ? $gettext('auto = CPU cores')
  191. : $gettext('manually set')
  192. }}
  193. </span>
  194. </p>
  195. <p class="mb-0">
  196. {{ $gettext('Tips: You can increase the concurrency processing capacity by increasing worker_processes or worker_connections') }}
  197. </p>
  198. </template>
  199. </AAlert>
  200. </div>
  201. </ATabPane>
  202. </ATabs>
  203. </ACard>
  204. </template>