PerformanceTablesCard.vue 5.7 KB

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