mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-28 06:05:24 +00:00
25 lines
857 B
TypeScript
25 lines
857 B
TypeScript
import type { ServerMetrics } from "@/main-axios";
|
|
|
|
/**
|
|
* Coarse fingerprint of a metrics poll. Adaptive polling backs off while it
|
|
* stays the same, so it must move whenever something a card shows changes.
|
|
*/
|
|
export function metricsChangeKey(data: ServerMetrics): string {
|
|
const bucket = (value: number | null | undefined) =>
|
|
value == null ? null : Math.round(value / 5) * 5;
|
|
return JSON.stringify({
|
|
cpu: bucket(data.cpu.percent),
|
|
memory: bucket(data.memory.percent),
|
|
disk: bucket(data.disk.percent),
|
|
running: data.processes?.running ?? null,
|
|
ports: data.ports?.ports?.length ?? 0,
|
|
firewall: data.firewall?.status ?? null,
|
|
gpus:
|
|
data.gpu?.gpus?.map((gpu) => [
|
|
bucket(gpu.utilizationPercent),
|
|
bucket(gpu.memoryPercent),
|
|
]) ?? [],
|
|
gpuProcesses: data.gpu?.processes?.length ?? 0,
|
|
});
|
|
}
|