SPB Git

Repository Public

metrics.ts 1.3 KB 22 lines typescript

1import type { I18n, TKey } from "@/i18n";23/** Metric families shown on the node detail screen, in display order, with the metrics of each. */4export const METRIC_FAMILIES = [5  { id: "cpu", metrics: ["cpu.usage", "cpu.user", "cpu.system", "load.1", "load.5", "load.15"] },6  { id: "memory", metrics: ["mem.used", "mem.wired", "mem.compressed", "mem.available.percent", "mem.pressure.level", "swap.used"] },7  { id: "disk", metrics: ["disk.read", "disk.write", "disk.used"] },8  { id: "network", metrics: ["net.rx", "net.tx", "net.errors", "net.latency", "net.loss"] },9  { id: "gpu", metrics: ["gpu.usage", "gpu.mem.used"] },10  { id: "thermal", metrics: ["thermal.pressure", "thermal.temp", "power.draw", "battery.charge"] },11  { id: "system", metrics: ["uptime", "procs.count"] },12  { id: "agent", metrics: ["agent.cpu", "agent.rss"] },13] as const;14export type MetricFamilyId = (typeof METRIC_FAMILIES)[number]["id"];1516const KNOWN = new Set<string>([...METRIC_FAMILIES.flatMap((f): string[] => [...f.metrics]), "mem.total", "swap.total", "disk.total"]);1718/** Localised label of a catalog metric. A metric this client does not know yet is shown by its catalog name. */19export function metricLabel(t: I18n["t"], name: string): string {20  return KNOWN.has(name) ? t(`metrics.${name.replace(/\./g, "_")}` as TKey) : name;21}22
Files main
Menu

Theme