feat: add container resource monitoring

This commit is contained in:
RuoJi6 authored and GitHub committed 2026-10-29 10:28:40 -07:00
1 parent 5527120089
commit 5366160a5d
6 files changed
+199 -1

No files matched your search

+46
View File
@@ -13,6 +13,9 @@ import {
ShieldCheckIcon,
TargetIcon,
ZapIcon,
CpuIcon,
HardDriveIcon,
MemoryStickIcon,
} from "lucide-react";
import { Bar, BarChart, CartesianGrid, Tooltip as RechartsTooltip, XAxis, YAxis } from "recharts";
@@ -38,6 +41,7 @@ import type {
Tool,
TrafficExchange,
UsageStats,
SystemMetrics,
} from "@/lib/types";
import { cn } from "@/lib/utils";
@@ -69,6 +73,15 @@ function fmtTokens(n: number): string {
return String(n);
}
function fmtBytes(n: number): string {
if (!n) return "—";
const units = ["B", "KB", "MB", "GB", "TB"];
let value = n;
let i = 0;
while (value >= 1024 && i < units.length - 1) { value /= 1024; i++; }
return `${value.toFixed(value >= 10 || i === 0 ? 0 : 1)} ${units[i]}`;
}
const ASSET_TYPE_LABELS: Record<string, string> = {
root_domain: "根域名",
ip: "IP",
@@ -147,6 +160,15 @@ export default function DashboardPage() {
const [skills, setSkills] = React.useState<SkillItem[]>([]);
const [tools, setTools] = React.useState<Tool[]>([]);
const [llmProfiles, setLLMProfiles] = React.useState<LLMProfile[]>([]);
const [systemMetrics, setSystemMetrics] = React.useState<SystemMetrics | null>(null);
React.useEffect(() => {
let alive = true;
const load = async () => { try { const m = await api.systemMetrics(); if (alive) setSystemMetrics(m); } catch { /* retry */ } };
void load();
const timer = setInterval(load, 5000);
return () => { alive = false; clearInterval(timer); };
}, []);
// The task list is the most expensive dashboard source. Poll it independently
// so a large history cannot hold back every other dashboard panel.
@@ -1129,6 +1151,30 @@ export default function DashboardPage() {
<Card className="p-4">
<SectionTitle icon={ShieldCheckIcon}>系统状态</SectionTitle>
{systemMetrics && (
<div className="mb-3 rounded-lg border bg-muted/20 p-3">
<div className="mb-2 flex items-center justify-between">
<span className="text-[10px] font-medium">容器资源</span>
<span className="text-[9px] text-muted-foreground">每 5 秒刷新</span>
</div>
<div className="grid grid-cols-3 gap-2">
{([
[CpuIcon, "CPU", systemMetrics.cpu],
[MemoryStickIcon, "内存", systemMetrics.memory],
[HardDriveIcon, "磁盘", systemMetrics.data_disk],
] as const).map(([Icon, label, metric]) => (
<div key={label} className="min-w-0">
<div className="mb-1 flex items-center gap-1 text-[9px] text-muted-foreground"><Icon className="size-3" />{label}</div>
<Progress value={metric.percent} className="h-1.5" />
<div className="mt-1 truncate text-[9px] tabular-nums">{metric.percent.toFixed(1)}%</div>
{label !== "CPU" && <div className="truncate text-[9px] text-muted-foreground">{fmtBytes(metric.used_bytes)} / {fmtBytes(metric.total_bytes)}</div>}
</div>
))}
</div>
<div className="mt-2 text-[9px] text-muted-foreground">监控范围:{systemMetrics.scope === "container" ? "ARTEX 容器" : "当前进程(非容器运行)"}</div>
</div>
)}
<div className="flex flex-col gap-2">
<div className="flex items-center justify-between rounded-lg border bg-muted/20 px-3 py-2">
<div className="text-[10px] text-muted-foreground">LLM 配置</div>
+2
View File
@@ -116,6 +116,7 @@ import type {
UsageStats,
WorkspaceFile,
WorkspaceListing,
SystemMetrics,
} from "@/lib/types";
function getToken(): string | null {
@@ -292,6 +293,7 @@ function schedulePayload(input: ScheduleInput) {
export const api = {
// 后端应用版本号(release 时由 ldflags 注入,默认 "dev")。
health: () => get<{ ok: boolean; service: string; version: string }>("/health"),
systemMetrics: () => get<SystemMetrics>("/system/metrics"),
// ---- auth ----
authStatus: () => get<{ initialized: boolean }>("/auth/status"),
+16
View File
@@ -1331,6 +1331,22 @@ export interface Stats {
active_task?: Partial<Task>;
}
export interface SystemMetricValue {
used_bytes: number;
total_bytes: number;
percent: number;
}
export interface SystemMetrics {
scope: "container" | string;
timestamp: string;
container_metrics: boolean;
cpu: SystemMetricValue;
memory: SystemMetricValue;
disk: SystemMetricValue;
data_disk: SystemMetricValue;
}
// ---- Intercept Rules ----
export type InterceptAction = "allow" | "deny" | "ask";
export type InterceptMatchTarget = "tool_name" | "tool_input";