From 7a47e34384e07f2354901229e11f848a461ec927 Mon Sep 17 00:00:00 2001 From: chenguo Date: Mon, 9 Sep 2024 18:59:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=80=90k8s=E7=9B=91=E6=8E=A7=E3=80=91?= =?UTF-8?q?=E3=80=90MF=E3=80=91=E4=BB=AA=E8=A1=A8=E7=9B=98=E6=95=B0?= =?UTF-8?q?=E5=80=BC=E8=BF=87=E9=95=BF=E5=AF=BC=E8=87=B4=E7=9A=84=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E9=97=AE=E9=A2=98=20--story=3D119558375=20(#2873)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scene_view/resources/kubernetes.py | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/bkmonitor/packages/monitor_web/scene_view/resources/kubernetes.py b/bkmonitor/packages/monitor_web/scene_view/resources/kubernetes.py index 752fed694..c85add332 100644 --- a/bkmonitor/packages/monitor_web/scene_view/resources/kubernetes.py +++ b/bkmonitor/packages/monitor_web/scene_view/resources/kubernetes.py @@ -60,6 +60,7 @@ from constants.data_source import DataSourceLabel, DataTypeLabel from constants.event import EventTypeNormal, EventTypeWarning from core.drf_resource import Resource, api, resource +from core.unit import load_unit from monitor_web.constants import ( GRAPH_COLUMN_BAR, GRAPH_NUMBER_CHART, @@ -3844,6 +3845,7 @@ def to_percentage_bar_graph(params: Dict, performance_data: List, top_n: int) -> sorted_data = sorted(data.items(), key=lambda d: d[1] if d[1] else 0, reverse=True)[:top_n] graph_data = [] for namespace, value in sorted_data: + # 不知道哪里调用这块, value 和 total 共用G 单位, 暂不改 graph_data.append( { "name": namespace, @@ -3870,9 +3872,9 @@ def to_number_resource_graph(self, params: Dict, performance_data: Dict) -> List value = 0 data[key_name] = value - allocatable_memory = round(data.get("allocatable_memory_bytes", 0) / 1024 / 1024 / 1024, 2) - requests_memory = round(data.get("requests_memory_bytes", 0) / 1024 / 1024 / 1024, 2) - limits_memory = round(data.get("limits_memory_bytes", 0) / 1024 / 1024 / 1024, 2) + allocatable_memory = data.get("allocatable_memory_bytes", 0) + requests_memory = data.get("requests_memory_bytes", 0) + limits_memory = data.get("limits_memory_bytes", 0) pre_allocatable_usage_ratio = round(data.get('pre_allocatable_usage_ratio', 0), 2) if pre_allocatable_usage_ratio > 80: @@ -3884,11 +3886,11 @@ def to_number_resource_graph(self, params: Dict, performance_data: Dict) -> List graph_data = [ { "name": _("内存 request 量"), - "value": f"{requests_memory}G", + "value": "%s %s" % load_unit("bytes").auto_convert(requests_memory, decimal=2), }, { "name": _("内存 limit 量"), - "value": f"{limits_memory}G", + "value": "%s %s" % load_unit("bytes").auto_convert(limits_memory, decimal=2), }, ] return graph_data @@ -3896,15 +3898,15 @@ def to_number_resource_graph(self, params: Dict, performance_data: Dict) -> List graph_data = [ { "name": _("内存总量"), - "value": f"{allocatable_memory}G", + "value": "%s %s" % load_unit("bytes").auto_convert(allocatable_memory, decimal=2), }, { "name": _("内存 request 量"), - "value": f"{requests_memory}G", + "value": "%s %s" % load_unit("bytes").auto_convert(requests_memory, decimal=2), }, { "name": _("内存 limit 量"), - "value": f"{limits_memory}G", + "value": "%s %s" % load_unit("bytes").auto_convert(limits_memory, decimal=2), }, { "name": _("内存预分配率"), @@ -4036,8 +4038,8 @@ def build_unify_query_iterable(params: Dict) -> List: @staticmethod def to_graph(validated_request_data: Dict, performance_data: List) -> List: - system_disk_total = round(performance_data.get("system_disk_total", 0) / 1024 / 1024 / 1024, 2) - system_disk_used = round(performance_data.get("system_disk_used", 0) / 1024 / 1024 / 1024, 2) + system_disk_total = performance_data.get("system_disk_total", 0) + system_disk_used = performance_data.get("system_disk_used", 0) disk_usage_ratio = round(performance_data.get('disk_usage_ratio', 0), 2) if disk_usage_ratio > 80: @@ -4047,11 +4049,11 @@ def to_graph(validated_request_data: Dict, performance_data: List) -> List: graph_data = [ { "name": _("磁盘总量"), - "value": f"{system_disk_total}G", + "value": "%s %s" % load_unit("bytes").auto_convert(system_disk_total, decimal=2), }, { "name": _("磁盘已使用量"), - "value": f"{system_disk_used}G", + "value": "%s %s" % load_unit("bytes").auto_convert(system_disk_used, decimal=2), }, { "name": _("磁盘使用率"),