From 88b264be69ebe32e214c04c3166a6b636705f483 Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Sun, 1 Dec 2024 16:54:39 +0800 Subject: [PATCH] feat: add chart detail --- src/components/ServerDetailChart.tsx | 40 +++++++++++++++++-------- src/components/ServerDetailOverview.tsx | 14 ++++++--- src/types/nezha-api.ts | 2 ++ 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/components/ServerDetailChart.tsx b/src/components/ServerDetailChart.tsx index 942d15e..19ab087 100644 --- a/src/components/ServerDetailChart.tsx +++ b/src/components/ServerDetailChart.tsx @@ -16,6 +16,7 @@ import { ServerDetailChartLoading } from "./loading/ServerDetailLoading"; import AnimatedCircularProgressBar from "./ui/animated-circular-progress-bar"; import { useWebSocketContext } from "@/hooks/use-websocket-context"; import { useTranslation } from "react-i18next"; +import { formatBytes } from "@/lib/format"; type cpuChartData = { timeStamp: string; @@ -317,7 +318,7 @@ function MemChart({ now, data }: { now: number; data: NezhaServer }) {
-
+

@@ -350,6 +351,15 @@ function MemChart({ now, data }: { now: number; data: NezhaServer }) {

+
+
+ {formatBytes(data.state.mem_used)} /{" "} + {formatBytes(data.state.mem_total)} +
+
+ swap: {formatBytes(data.state.swap_used)} +
+

{t("serverDetailChart.disk")}

-
-

- {disk.toFixed(0)}% -

- +
+
+

+ {disk.toFixed(0)}% +

+ +
+
+ {formatBytes(data.state.disk_used)} /{" "} + {formatBytes(data.state.disk_total)} +
- +

{"Load"}

@@ -198,7 +198,9 @@ export default function ServerDetailOverview({ {server.state.load_1} / {server.state.load_5} /{" "} {server.state.load_15} - ) : null} + ) : ( +
{t("serverDetail.unknown")}
+ )}
@@ -213,7 +215,9 @@ export default function ServerDetailOverview({ {" "} {formatBytes(server.state.net_out_transfer)}{" "} - ) : null} + ) : ( +
{t("serverDetail.unknown")}
+ )}
@@ -228,7 +232,9 @@ export default function ServerDetailOverview({ {" "} {formatBytes(server.state.net_in_transfer)}{" "} - ) : null} + ) : ( +
{t("serverDetail.unknown")}
+ )} diff --git a/src/types/nezha-api.ts b/src/types/nezha-api.ts index 5f15971..976785c 100644 --- a/src/types/nezha-api.ts +++ b/src/types/nezha-api.ts @@ -28,8 +28,10 @@ export interface NezhaServerHost { export interface NezhaServerStatus { cpu: number; mem_used: number; + mem_total: number; swap_used: number; disk_used: number; + disk_total: number; net_in_transfer: number; net_out_transfer: number; net_in_speed: number;