mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-11-29 11:01:50 +08:00
fix: support non-Linux resource status builds
This commit is contained in:
1 parent
08cf862b0c
commit
df9d38af0d
7 files changed
+124
-120
No files matched your search
@@ -6,9 +6,11 @@ import { usePathname } from "next/navigation";
|
||||
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { SidebarTrigger } from "@/components/ui/sidebar";
|
||||
import { CpuIcon, HardDriveIcon, MemoryStickIcon } from "lucide-react";
|
||||
import { useCurrentUser } from "@/hooks/use-current-user";
|
||||
import { api } from "@/lib/api";
|
||||
import { cn } from "@/lib/utils";
|
||||
import type { SystemMetrics } from "@/lib/types";
|
||||
|
||||
import { EgressIpNavbar, EgressIpProvider } from "./egress-ip-banner";
|
||||
import { LiveClock } from "./live-clock";
|
||||
@@ -76,6 +78,7 @@ function MainContentInner({ children }: { children: ReactNode }) {
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<EgressIpNavbar />
|
||||
<SystemResourceNavbar />
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center gap-2">
|
||||
<LiveClock />
|
||||
@@ -95,3 +98,42 @@ function MainContentInner({ children }: { children: ReactNode }) {
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function SystemResourceNavbar() {
|
||||
const [metrics, setMetrics] = useState<SystemMetrics | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
const load = async () => {
|
||||
try {
|
||||
const next = await api.systemMetrics();
|
||||
if (alive) setMetrics(next);
|
||||
} catch {
|
||||
/* Keep the status bar quiet while the API is unavailable. */
|
||||
}
|
||||
};
|
||||
void load();
|
||||
const timer = setInterval(load, 5000);
|
||||
return () => { alive = false; clearInterval(timer); };
|
||||
}, []);
|
||||
|
||||
if (!metrics) return null;
|
||||
if (!metrics.supported) {
|
||||
return <div className="flex items-center justify-center text-xs text-muted-foreground" role="status">资源状态:暂不支持</div>;
|
||||
}
|
||||
const items = [
|
||||
[CpuIcon, "CPU", metrics.cpu.percent],
|
||||
[MemoryStickIcon, "内存", metrics.memory.percent],
|
||||
[HardDriveIcon, "磁盘", metrics.data_disk.percent],
|
||||
] as const;
|
||||
return (
|
||||
<div className="flex items-center justify-center gap-3 text-[10px] text-muted-foreground" role="status" aria-live="polite">
|
||||
<span>容器资源</span>
|
||||
{items.map(([Icon, label, value]) => (
|
||||
<span key={label} className="inline-flex items-center gap-1 tabular-nums" title={`${label} ${value.toFixed(1)}%`}>
|
||||
<Icon className="size-3" aria-hidden="true" /> {label} {value.toFixed(1)}%
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -13,9 +13,6 @@ import {
|
||||
ShieldCheckIcon,
|
||||
TargetIcon,
|
||||
ZapIcon,
|
||||
CpuIcon,
|
||||
HardDriveIcon,
|
||||
MemoryStickIcon,
|
||||
} from "lucide-react";
|
||||
import { Bar, BarChart, CartesianGrid, Tooltip as RechartsTooltip, XAxis, YAxis } from "recharts";
|
||||
|
||||
@@ -41,7 +38,6 @@ import type {
|
||||
Tool,
|
||||
TrafficExchange,
|
||||
UsageStats,
|
||||
SystemMetrics,
|
||||
} from "@/lib/types";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
@@ -73,15 +69,6 @@ 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",
|
||||
@@ -160,15 +147,6 @@ 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.
|
||||
@@ -1151,30 +1129,6 @@ 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>
|
||||
|
||||
@@ -1338,7 +1338,8 @@ export interface SystemMetricValue {
|
||||
}
|
||||
|
||||
export interface SystemMetrics {
|
||||
scope: "container" | string;
|
||||
scope: "container" | "unsupported" | string;
|
||||
supported: boolean;
|
||||
timestamp: string;
|
||||
container_metrics: boolean;
|
||||
cpu: SystemMetricValue;
|
||||
|
||||
Reference in new issue
Block a user