ResourceUsageCard.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <script setup lang="ts">
  2. import type { NginxPerformanceInfo } from '@/api/ngx'
  3. import {
  4. FundProjectionScreenOutlined,
  5. InfoCircleOutlined,
  6. ThunderboltOutlined,
  7. } from '@ant-design/icons-vue'
  8. import { computed, defineProps } from 'vue'
  9. const props = defineProps<{
  10. nginxInfo: NginxPerformanceInfo
  11. }>()
  12. // 资源利用率
  13. const resourceUtilization = computed(() => {
  14. const cpuFactor = Math.min(props.nginxInfo.cpu_usage / 100, 1)
  15. const maxConnections = props.nginxInfo.worker_connections * props.nginxInfo.worker_processes
  16. const connectionFactor = Math.min(props.nginxInfo.active / maxConnections, 1)
  17. return Math.round((cpuFactor * 0.5 + connectionFactor * 0.5) * 100)
  18. })
  19. </script>
  20. <template>
  21. <ACard :title="$gettext('Resource Usage of Nginx')" :bordered="false" class="h-full" :body-style="{ padding: '16px', height: 'calc(100% - 58px)' }">
  22. <div class="flex flex-col h-full">
  23. <!-- CPU使用率 -->
  24. <ARow :gutter="[16, 8]" class="mb-2">
  25. <ACol :span="24">
  26. <div class="flex items-center">
  27. <ThunderboltOutlined class="text-lg mr-2" :style="{ color: nginxInfo.cpu_usage > 80 ? '#cf1322' : '#3f8600' }" />
  28. <div class="text-base font-medium">
  29. {{ $gettext('CPU Usage') }}: <span :style="{ color: nginxInfo.cpu_usage > 80 ? '#cf1322' : '#3f8600' }">{{ nginxInfo.cpu_usage.toFixed(2) }}%</span>
  30. </div>
  31. </div>
  32. <AProgress
  33. :percent="Math.min(nginxInfo.cpu_usage, 100)"
  34. :format="percent => `${percent?.toFixed(2)}%`"
  35. :status="nginxInfo.cpu_usage > 80 ? 'exception' : 'active'"
  36. size="small"
  37. class="mt-1"
  38. :show-info="false"
  39. />
  40. <div v-if="nginxInfo.cpu_usage > 50" class="text-xs text-orange-500 mt-1">
  41. {{ $gettext('CPU usage is relatively high, consider optimizing Nginx configuration') }}
  42. </div>
  43. </ACol>
  44. </ARow>
  45. <!-- 内存使用 -->
  46. <ARow :gutter="[16, 8]" class="mb-2">
  47. <ACol :span="24">
  48. <div class="flex items-center">
  49. <div class="text-blue-500 text-lg mr-2 flex items-center">
  50. <FundProjectionScreenOutlined />
  51. </div>
  52. <div class="text-base font-medium">
  53. {{ $gettext('Memory Usage(RSS)') }}: <span class="text-blue-500">{{ nginxInfo.memory_usage.toFixed(2) }} MB</span>
  54. </div>
  55. <ATooltip :title="$gettext('Resident Set Size: Actual memory resident in physical memory, including all shared library memory, which will be repeated calculated for multiple processes')">
  56. <InfoCircleOutlined class="ml-1 text-gray-500" />
  57. </ATooltip>
  58. </div>
  59. </ACol>
  60. </ARow>
  61. <div class="mt-1 flex justify-between text-xs text-gray-500">
  62. {{ $gettext('Per worker memory') }}: {{ (nginxInfo.memory_usage / (nginxInfo.workers || 1)).toFixed(2) }} MB
  63. </div>
  64. <!-- 系统负载 -->
  65. <div class="mt-4 text-xs text-gray-500 border-t border-gray-100 pt-2">
  66. <div class="flex justify-between mb-1">
  67. <span>{{ $gettext('System load') }}</span>
  68. <span class="font-medium">{{ resourceUtilization }}%</span>
  69. </div>
  70. <AProgress
  71. :percent="resourceUtilization"
  72. size="small"
  73. :status="resourceUtilization > 80 ? 'exception' : 'active'"
  74. :stroke-color="resourceUtilization > 80 ? '#ff4d4f' : resourceUtilization > 50 ? '#faad14' : '#52c41a'"
  75. :show-info="false"
  76. />
  77. </div>
  78. </div>
  79. </ACard>
  80. </template>