Skip to content

Commit

Permalink
feat: 【k8s监控】【MF】仪表盘数值过长导致的样式问题 --story=119558375 (#2873)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenguo367 authored Sep 9, 2024
1 parent a3e138c commit 7a47e34
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions bkmonitor/packages/monitor_web/scene_view/resources/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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:
Expand All @@ -3884,27 +3886,27 @@ 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

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": _("内存预分配率"),
Expand Down Expand Up @@ -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:
Expand All @@ -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": _("磁盘使用率"),
Expand Down

0 comments on commit 7a47e34

Please sign in to comment.