Add a status strip to the server page: status, maintenance, alerts, updates, disk, load and uptime at a glance

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-11-06 23:21:57 +01:00
1 parent f9991a49af
commit 87e07b2209
5 files changed
+369

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
import { Link } from "react-router-dom";
import type { AlertItem, HealthCheckSettings, MaintenanceWindow, ServerHardware, ServerRecord } from "../api/client";
import { serverStrip, type StripTile, type StripTone } from "../utils/serverStrip";
const TEXT: Record<StripTone, string> = { ok: "text-green", warn: "text-yellow", bad: "text-red", info: "text-blue", muted: "" };
function Tile({ t }: { t: StripTile }) {
const body = (
<div className="card card-sm h-100">
<div className="card-body py-2 px-3">
<div className="text-secondary small">{t.label}</div>
<div className={`fw-bold ${t.tone === "muted" ? "" : TEXT[t.tone]}`} style={{ fontSize: "1.15rem", lineHeight: 1.25 }}>
{t.value}
</div>
{t.sub && <div className="text-secondary small text-truncate" title={t.sub}>{t.sub}</div>}
</div>
</div>
);
return (
<div className="col-6 col-md-4 col-xl">
{t.to ? (
<Link to={t.to} className="text-reset text-decoration-none d-block h-100">
{body}
</Link>
) : (
body
)}
</div>
);
}
/**
* How the server is, in a row under its name — on every section of its page: whether it reports (or is offline), whether it is in maintenance, what is open about it, what is waiting to be
* installed, how full its disk is, how busy it is and how long it has run. What it is built from is in utils/serverStrip.ts.
*/
export default function ServerStatusStrip({ server, hardware, defaults, alerts, windows }: { server: ServerRecord; hardware: ServerHardware; defaults: HealthCheckSettings; alerts: AlertItem[] | null; windows: MaintenanceWindow[] | null }) {
const tiles = serverStrip({ server, hardware, defaults, alerts, windows });
return (
<div className="row g-2 mb-3" role="group" aria-label="How this server is">
{tiles.map((t) => (
<Tile key={t.id} t={t} />
))}
</div>
);
}
+24
View File
@@ -9,6 +9,8 @@ import {
type ProxmoxGuest,
type ScheduleType,
type ServerDetail as ServerDetailResponse,
type AlertItem,
type MaintenanceWindow,
type ServerLink,
type TaskRecord,
} from "../api/client";
@@ -44,6 +46,7 @@ import ViewTabs from "../components/ViewTabs";
import ConnectedThrough from "../components/ConnectedThrough";
import HetznerServerCard from "../components/HetznerServerCard";
import ServerBlock, { ArrangeBar } from "../components/ServerBlock";
import ServerStatusStrip from "../components/ServerStatusStrip";
const SCHEDULE_TYPE_OPTIONS: { value: ScheduleType; label: string }[] = Object.entries(SCHEDULE_TYPE_LABELS).map(
([value, label]) => ({ value: value as ScheduleType, label }),
@@ -173,6 +176,25 @@ export default function ServerDetail({ user }: { user: CurrentUser }) {
});
}, [serverId]);
// What the strip under the name says that is not in the server's own record: the alerts about it and the maintenance windows. Read again whenever the page is (the Refresh button).
const [stripAlerts, setStripAlerts] = useState<AlertItem[] | null>(null);
const [stripWindows, setStripWindows] = useState<MaintenanceWindow[] | null>(null);
useEffect(() => {
if (!detail) return;
let live = true;
api.alerts
.list()
.then((r) => live && setStripAlerts(r.alerts))
.catch(() => live && setStripAlerts(null));
api.maintenance
.list()
.then((r) => live && setStripWindows(r.windows))
.catch(() => live && setStripWindows(null));
return () => {
live = false;
};
}, [detail]);
const loadTasks = useCallback(() => {
api.tasks
.list({ serverId, includeStale: true })
@@ -434,6 +456,8 @@ export default function ServerDetail({ user }: { user: CurrentUser }) {
</div>
<ErrorNotice error={error} />
<ServerStatusStrip server={server} hardware={detail.hardware} defaults={detail.thresholdDefaults} alerts={stripAlerts} windows={stripWindows} />
<ServerTags
serverId={serverId}
tags={server.tags}
+139
View File
@@ -0,0 +1,139 @@
import type { AlertItem, HealthCheckSettings, MaintenanceWindow, ServerHardware, ServerRecord } from "../api/client";
import { formatAgo, formatRemaining } from "./duration";
/** How a figure reads: fine, to be watched, wrong, merely information, or not known. */
export type StripTone = "ok" | "warn" | "bad" | "info" | "muted";
export interface StripTile {
id: "status" | "maintenance" | "alerts" | "updates" | "disk" | "load" | "uptime";
label: string;
value: string;
sub: string | null;
tone: StripTone;
/** A page it leads to. */
to?: string;
}
export interface StripInput {
server: ServerRecord;
hardware: ServerHardware;
/** The limits in Settings, which the server follows wherever it has none of its own. */
defaults: HealthCheckSettings;
/** Null while they have not been loaded (or could not be). */
alerts: AlertItem[] | null;
windows: MaintenanceWindow[] | null;
now?: number;
}
const plural = (n: number, one: string, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
/** "12d 4h", "3h 20m". */
export function uptimeText(seconds: number): string {
const days = Math.floor(seconds / 86400);
const hours = Math.floor((seconds % 86400) / 3600);
if (days > 0) return `${days}d ${hours}h`;
return `${hours}h ${Math.floor((seconds % 3600) / 60)}m`;
}
/** Pure: what is wrong with a disk's fullness, against its own limit (a mount may have its own, or be ignored): the worst of them, as "87% on /". */
export function worstDisk(hardware: ServerHardware, server: Pick<ServerRecord, "thresholds">, defaults: Pick<HealthCheckSettings, "diskUsagePercent">): { mount: string; percent: number; limit: number; of: number } | null {
const base = server.thresholds?.diskUsagePercent ?? defaults.diskUsagePercent;
let worst: { mount: string; percent: number; limit: number; margin: number } | null = null;
let counted = 0;
for (const d of hardware.disks ?? []) {
if (!(d.sizeBytes > 0)) continue;
const rule = server.thresholds?.mounts?.[d.mount];
if (rule?.ignore) continue;
counted++;
const percent = Math.round((d.usedBytes / d.sizeBytes) * 100);
const limit = rule?.percent ?? base;
const margin = percent - limit;
if (worst === null || margin > worst.margin) worst = { mount: d.mount, percent, limit, margin };
}
return worst && { mount: worst.mount, percent: worst.percent, limit: worst.limit, of: counted };
}
/**
* Pure: the figures that say at a glance how a server is — whether it reports, whether it is in maintenance, what is open about it, what is waiting to be installed, how full its disk is, how busy it is
* and how long it has run — each with a tone and, where there is one, the page to go to. A figure that cannot be told (nothing reported, nothing loaded) is left out or says so, never made up.
*/
export function serverStrip(i: StripInput): StripTile[] {
const now = i.now ?? Date.now();
const { server, hardware, defaults } = i;
const tiles: StripTile[] = [];
// Whether it reports.
const offlineMinutes = server.thresholds?.serverOfflineMinutes ?? defaults.serverOfflineMinutes;
const viaProxmox = hardware.source === "proxmox" && hardware.status ? hardware.status : null;
if (server.lastSeenAt) {
const age = (now - Date.parse(server.lastSeenAt)) / 60_000;
if (age > offlineMinutes) {
tiles.push({ id: "status", label: "Status", value: "Offline", sub: `last report ${formatAgo(server.lastSeenAt, now)}${viaProxmox === "running" ? " — Proxmox says it is running" : ""}`, tone: "bad" });
} else {
tiles.push({ id: "status", label: "Status", value: "Online", sub: `reported ${formatAgo(server.lastSeenAt, now)}`, tone: "ok" });
}
} else if (viaProxmox) {
tiles.push({ id: "status", label: "Status", value: viaProxmox.charAt(0).toUpperCase() + viaProxmox.slice(1), sub: "from Proxmox — no agent report", tone: viaProxmox === "running" ? "ok" : "warn" });
} else {
tiles.push({ id: "status", label: "Status", value: "No report yet", sub: "its agent has not reported", tone: "muted" });
}
// A maintenance window that is on now.
const active = (i.windows ?? [])
.filter((w) => w.targetType === "server" && w.targetId === server.id && Date.parse(w.startedAt) <= now && Date.parse(w.endsAt) > now)
.sort((a, b) => Date.parse(a.endsAt) - Date.parse(b.endsAt))[0];
if (active) tiles.push({ id: "maintenance", label: "Maintenance", value: "On now", sub: `ends in ${formatRemaining(active.endsAt, now)}${active.reason ? ` — ${active.reason}` : ""}`, tone: "info", to: "/maintenance" });
// What is open about it (what a window or a snooze has put aside is not counted, but said).
if (i.alerts === null) {
tiles.push({ id: "alerts", label: "Alerts", value: "—", sub: "not loaded", tone: "muted", to: "/alerts" });
} else {
const mine = i.alerts.filter((a) => a.target?.type === "server" && a.target.id === server.id);
const open = mine.filter((a) => !a.silenced && !a.snoozed && !a.closed);
const critical = open.filter((a) => a.severity === "critical").length;
const warning = open.filter((a) => a.severity === "warning").length;
const aside = mine.length - open.length;
const parts = [critical > 0 ? plural(critical, "critical", "critical") : null, warning > 0 ? plural(warning, "warning") : null].filter(Boolean) as string[];
tiles.push({
id: "alerts",
label: "Alerts",
value: critical + warning === 0 ? "None" : String(critical + warning),
sub: [parts.join(" · "), aside > 0 ? `${aside} set aside` : ""].filter(Boolean).join(" · ") || "nothing open",
tone: critical > 0 ? "bad" : warning > 0 ? "warn" : "ok",
to: "/alerts",
});
}
// What is waiting to be installed.
const u = server.pendingUpdates;
if (u === null) {
tiles.push({ id: "updates", label: "Updates", value: "Not reported", sub: "the agent has not said", tone: "muted", to: "/updates" });
} else {
const security = u.security !== null && u.security > 0;
tiles.push({
id: "updates",
label: "Updates",
value: u.count === 0 ? "Up to date" : `${u.count} waiting`,
sub: [u.count > 0 && u.security !== null ? `${u.security} security` : "", u.rebootRequired ? "reboot needed" : ""].filter(Boolean).join(" · ") || null,
tone: security || u.rebootRequired ? "warn" : u.count > 0 ? "info" : "ok",
to: "/updates",
});
}
// The fullest disk, against its own limit.
const disk = worstDisk(hardware, server, defaults);
if (disk) {
tiles.push({ id: "disk", label: "Disk", value: `${disk.percent}%`, sub: `${disk.mount}${disk.of > 1 ? ` — fullest of ${disk.of}` : ""}`, tone: disk.percent >= disk.limit ? "bad" : disk.percent >= disk.limit - 10 ? "warn" : "ok" });
}
// How busy it is.
const cpu = hardware.cpuUsagePercent ?? hardware.cpuLoadPercent ?? null;
const mem = hardware.memTotalBytes ? Math.round(((hardware.memUsedBytes ?? 0) / hardware.memTotalBytes) * 100) : null;
if (cpu !== null || mem !== null) {
const busy = (cpu ?? 0) >= 90 || (mem ?? 0) >= 90;
tiles.push({ id: "load", label: "CPU · memory", value: [cpu !== null ? `${Math.round(cpu)}%` : "—", mem !== null ? `${mem}%` : "—"].join(" · "), sub: null, tone: busy ? "warn" : "muted" });
}
if (typeof hardware.uptime === "number" && hardware.uptime > 0) tiles.push({ id: "uptime", label: "Up for", value: uptimeText(hardware.uptime), sub: null, tone: "muted" });
return tiles;
}