Phone card layout, status symbols, breadcrumbs, integration cards and server trends
Tables stack into labelled cards on a phone. Green, red and amber badges carry a check, cross or triangle as well as their colour. Pages inside a menu group show a breadcrumb, with the thing's name on a server's page. Integrations are cards with an Open button and a live status (working, failing, not checked yet, disabled). Agent-reported servers keep a short history of load, memory and disk use (migration 0019, one sample per ten minutes for 35 days) and show it as a Trends card with a days-until-full forecast for a filling disk. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
617dc1ea2f
commit
9965d94036
22 files changed
+3000
-84
No files matched your search
@@ -0,0 +1,94 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { api, type ServerMetricSeries } from "../api/client";
|
||||
import Sparkline from "./Sparkline";
|
||||
|
||||
const RANGES = [
|
||||
{ days: 1, label: "24 hours" },
|
||||
{ days: 7, label: "7 days" },
|
||||
{ days: 30, label: "30 days" },
|
||||
];
|
||||
|
||||
function levelColor(series: ServerMetricSeries): string {
|
||||
const v = series.latest ?? 0;
|
||||
if (series.kind === "disk") return v >= 90 ? "#f03e3e" : v >= 80 ? "#f59f00" : "#4299e1";
|
||||
return "#4299e1";
|
||||
}
|
||||
|
||||
/** One line of words about where a series is heading: a disk's rate and when it fills, or a load/memory range. */
|
||||
function describeTrend(series: ServerMetricSeries): string {
|
||||
if (series.kind === "disk" && series.trend) {
|
||||
const { perDay, daysToFull } = series.trend;
|
||||
if (daysToFull !== null) return `rising ${perDay.toFixed(1)} points a day — full in about ${daysToFull} day${daysToFull === 1 ? "" : "s"}`;
|
||||
if (perDay <= -0.05) return `falling ${Math.abs(perDay).toFixed(1)} points a day`;
|
||||
return "steady";
|
||||
}
|
||||
if (series.kind === "disk") return "not enough history for a trend yet";
|
||||
const values = series.points.map((p) => p.v);
|
||||
if (values.length === 0) return "";
|
||||
return `${Math.round(Math.min(...values))}–${Math.round(Math.max(...values))}% over this time`;
|
||||
}
|
||||
|
||||
/** How an agent-reported server's load, memory and disks have moved lately, with a forecast for a filling disk. */
|
||||
export default function ServerTrends({ serverId }: { serverId: number }) {
|
||||
const [days, setDays] = useState(7);
|
||||
const [series, setSeries] = useState<ServerMetricSeries[] | null>(null);
|
||||
const [failed, setFailed] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
setFailed(false);
|
||||
api.servers
|
||||
.metrics(serverId, days)
|
||||
.then((res) => alive && setSeries(res.series))
|
||||
.catch(() => alive && setFailed(true));
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [serverId, days]);
|
||||
|
||||
return (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Trends</h3>
|
||||
<div className="card-actions">
|
||||
<select className="form-select form-select-sm" value={days} onChange={(e) => setDays(Number(e.target.value))} aria-label="Time range">
|
||||
{RANGES.map((r) => (
|
||||
<option key={r.days} value={r.days}>
|
||||
Last {r.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
{failed ? (
|
||||
<div className="text-secondary">Couldn't load the history.</div>
|
||||
) : series === null ? (
|
||||
<div className="text-secondary">Loading…</div>
|
||||
) : series.length === 0 ? (
|
||||
<div className="text-secondary">
|
||||
No history yet. A sample is kept about every ten minutes once the agent has reported, so lines appear here after a short while.
|
||||
</div>
|
||||
) : (
|
||||
<div className="trend-grid">
|
||||
{series.map((s) => {
|
||||
const words = describeTrend(s);
|
||||
return (
|
||||
<div key={s.metric} className="trend-row">
|
||||
<div className="trend-label">{s.label}</div>
|
||||
<Sparkline
|
||||
points={s.points}
|
||||
color={levelColor(s)}
|
||||
label={`${s.label}, ${s.latest !== null ? `${Math.round(s.latest)}% now` : "no reading"}${words ? `, ${words}` : ""}`}
|
||||
/>
|
||||
<div className="trend-now">{s.latest !== null ? `${Math.round(s.latest)}%` : "—"}</div>
|
||||
<div className="trend-words text-secondary small">{words}</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user