Skip to content

Commit

Permalink
feat: add chart detail
Browse files Browse the repository at this point in the history
  • Loading branch information
hamster1963 committed Dec 1, 2024
1 parent 90b87ee commit 88b264b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 16 deletions.
40 changes: 28 additions & 12 deletions src/components/ServerDetailChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -317,7 +318,7 @@ function MemChart({ now, data }: { now: number; data: NezhaServer }) {
<Card>
<CardContent className="px-6 py-3">
<section className="flex flex-col gap-1">
<div className="flex items-center">
<div className="flex items-center justify-between">
<section className="flex items-center gap-4">
<div className="flex flex-col">
<p className=" text-xs text-muted-foreground">
Expand Down Expand Up @@ -350,6 +351,15 @@ function MemChart({ now, data }: { now: number; data: NezhaServer }) {
</div>
</div>
</section>
<section className="flex flex-col items-end gap-0.5">
<div className="flex text-[11px] font-medium items-center gap-2">
{formatBytes(data.state.mem_used)} /{" "}
{formatBytes(data.state.mem_total)}
</div>
<div className="flex text-[11px] font-medium items-center gap-2">
swap: {formatBytes(data.state.swap_used)}
</div>
</section>
</div>
<ChartContainer
config={chartConfig}
Expand Down Expand Up @@ -443,17 +453,23 @@ function DiskChart({ now, data }: { now: number; data: NezhaServer }) {
<section className="flex flex-col gap-1">
<div className="flex items-center justify-between">
<p className="text-md font-medium">{t("serverDetailChart.disk")}</p>
<section className="flex items-center gap-2">
<p className="text-xs text-end w-10 font-medium">
{disk.toFixed(0)}%
</p>
<AnimatedCircularProgressBar
className="size-3 text-[0px]"
max={100}
min={0}
value={disk}
primaryColor="hsl(var(--chart-5))"
/>
<section className="flex flex-col items-end gap-0.5">
<section className="flex items-center gap-2">
<p className="text-xs text-end w-10 font-medium">
{disk.toFixed(0)}%
</p>
<AnimatedCircularProgressBar
className="size-3 text-[0px]"
max={100}
min={0}
value={disk}
primaryColor="hsl(var(--chart-5))"
/>
</section>
<div className="flex text-[11px] font-medium items-center gap-2">
{formatBytes(data.state.disk_used)} /{" "}
{formatBytes(data.state.disk_total)}
</div>
</section>
</div>
<ChartContainer
Expand Down
14 changes: 10 additions & 4 deletions src/components/ServerDetailOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export default function ServerDetailOverview({
</Card>
</section>
<section className="flex flex-wrap gap-2 mt-1">
<Card className="rounded-[10px] bg-transparent border-none shadow-none">
<Card className="rounded-[10px] bg-transparent border-none shadow-none">
<CardContent className="px-1.5 py-1">
<section className="flex flex-col items-start gap-0.5">
<p className="text-xs text-muted-foreground">{"Load"}</p>
Expand All @@ -198,7 +198,9 @@ export default function ServerDetailOverview({
{server.state.load_1} / {server.state.load_5} /{" "}
{server.state.load_15}
</div>
) : null}
) : (
<div className="text-xs"> {t("serverDetail.unknown")}</div>
)}
</section>
</CardContent>
</Card>
Expand All @@ -213,7 +215,9 @@ export default function ServerDetailOverview({
{" "}
{formatBytes(server.state.net_out_transfer)}{" "}
</div>
) : null}
) : (
<div className="text-xs"> {t("serverDetail.unknown")}</div>
)}
</section>
</CardContent>
</Card>
Expand All @@ -228,7 +232,9 @@ export default function ServerDetailOverview({
{" "}
{formatBytes(server.state.net_in_transfer)}{" "}
</div>
) : null}
) : (
<div className="text-xs"> {t("serverDetail.unknown")}</div>
)}
</section>
</CardContent>
</Card>
Expand Down
2 changes: 2 additions & 0 deletions src/types/nezha-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 88b264b

Please sign in to comment.