From 2c245261b5b5c4476440a4bc786a25b52dd85c1b Mon Sep 17 00:00:00 2001 From: Rivery <9858560+xigongdaEricyang@users.noreply.github.com> Date: Fri, 14 Apr 2023 15:28:02 +0800 Subject: [PATCH] feat: add memory usage utilization panel (#239) --- src/config/locale/en-US/device.json | 1 + .../locale/en-US/metric_description.json | 4 ++++ src/config/locale/zh-CN/device.json | 1 + .../locale/zh-CN/metric_description.json | 4 ++++ src/utils/promQL.ts | 23 +++++++++++++++++++ 5 files changed, 33 insertions(+) diff --git a/src/config/locale/en-US/device.json b/src/config/locale/en-US/device.json index d408f52e..8e0023b2 100644 --- a/src/config/locale/en-US/device.json +++ b/src/config/locale/en-US/device.json @@ -7,6 +7,7 @@ "openfiledesc": "Open File Desc & Context Switch", "diskIONum": "Disk IO Capacity", "memory": "Memory", + "memoryPercentage": "Memory Utilization", "load": "Load", "network": "Network", "networkIn": "Network In", diff --git a/src/config/locale/en-US/metric_description.json b/src/config/locale/en-US/metric_description.json index 73361e5a..840faafd 100644 --- a/src/config/locale/en-US/metric_description.json +++ b/src/config/locale/en-US/metric_description.json @@ -151,6 +151,10 @@ "memory_avaliable": "avaliable", "memory_cached": "cache + buffer", "memory_swap_used": "SWAP used", + "memory_currnet_used_utilization": "used", + "memory_avaliable_utilization": "available", + "memory_cached_utilization": "cache + buffer", + "memory_swap_utilization": "SWAP", "cpu_load_1": "load 1min", "cpu_load_5": "load 5min", "cpu_load_15": "load 15min", diff --git a/src/config/locale/zh-CN/device.json b/src/config/locale/zh-CN/device.json index ad4cc202..d54d176c 100644 --- a/src/config/locale/zh-CN/device.json +++ b/src/config/locale/zh-CN/device.json @@ -4,6 +4,7 @@ "cpu": "CPU", "disk": "磁盘", "memory": "内存", + "memoryPercentage": "内存使用率", "diskIO": "磁盘读写速率(IOPS)", "openfiledesc": "打开文件描述符&上下文切换", "diskIONum": "磁盘读写容量", diff --git a/src/config/locale/zh-CN/metric_description.json b/src/config/locale/zh-CN/metric_description.json index 097273e5..8c6eb474 100644 --- a/src/config/locale/zh-CN/metric_description.json +++ b/src/config/locale/zh-CN/metric_description.json @@ -150,6 +150,10 @@ "memory_avaliable": "可用", "memory_cached": "缓存", "memory_swap_used": "SWAP 用量", + "memory_currnet_used_utilization": "已使用率", + "memory_avaliable_utilization": "可用率", + "memory_cached_utilization": "缓存使用率", + "memory_swap_utilization": "SWAP 使用率", "cpu_load_1": "1分钟负载", "cpu_load_5": "5分钟负载", "cpu_load_15": "15分钟负载", diff --git a/src/utils/promQL.ts b/src/utils/promQL.ts index d28528a3..f3c33de1 100644 --- a/src/utils/promQL.ts +++ b/src/utils/promQL.ts @@ -317,6 +317,29 @@ export const getMachineMetricData = (instance, cluster) => { } ] }, + memory_utilization: { + title: intl.get('device.memoryPercentage'), + valueType: VALUE_TYPE.percentage, + viewPath: `/machine-metric/memory_utilization/${encodedInstance}`, + queries: [ + { + refId: 'memory_currnet_used_utilization', + query: `(node_memory_MemTotal_bytes{${instanceSuffix}${clusterSuffix1}} - node_memory_MemAvailable_bytes{${instanceSuffix}${clusterSuffix1}}) / (node_memory_MemTotal_bytes{${instanceSuffix}${clusterSuffix1}}) * 100`, + }, + { + refId: 'memory_avaliable_utilization', + query: `node_memory_MemAvailable_bytes{${instanceSuffix}${clusterSuffix1}} / (node_memory_MemTotal_bytes{${instanceSuffix}${clusterSuffix1}}) * 100`, + }, + { + refId: 'memory_cached_utilization', + query: `(node_memory_Buffers_bytes{${instanceSuffix}${clusterSuffix1}} + node_memory_Cached_bytes{${instanceSuffix}${clusterSuffix1}}) / (node_memory_MemTotal_bytes{${instanceSuffix}${clusterSuffix1}}) * 100`, + }, + { + refId: 'memory_swap_utilization', + query: `(node_memory_SwapTotal_bytes{${instanceSuffix}${clusterSuffix1}} - node_memory_SwapFree_bytes{${instanceSuffix}${clusterSuffix1}}) / (node_memory_MemTotal_bytes{${instanceSuffix}${clusterSuffix1}}) * 100`, + }, + ] + }, memory: { title: intl.get('device.memory'), valueType: VALUE_TYPE.byte,