What is normal for the time: baselines per hour of the week
Each server's CPU load and memory use get a baseline for every hour of the week (median and robust spread over up to ten weeks, four needed). A clearly high last hour that never dropped back toward normal is a warning; everything else stays quiet. Server History -> Trends draws a usual line and band. Setting under Notifications, on by default. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
232a5661ab
commit
31044b2b64
17 files changed
+619
-10
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { api, type ServerMetricSeries } from "../api/client";
|
||||
import { api, type BaselineView, type ServerMetricSeries } from "../api/client";
|
||||
import { hourOfWeek } from "../utils/hourOfWeek";
|
||||
import TimeChart from "./TimeChart";
|
||||
import RangeSelect from "./RangeSelect";
|
||||
import { BlockSkeleton } from "./Skeleton";
|
||||
@@ -33,6 +34,7 @@ export default function ServerTrends({ serverId }: { serverId: number }) {
|
||||
const [days, setDays] = useChartRange(7);
|
||||
const [series, setSeries] = useState<ServerMetricSeries[] | null>(null);
|
||||
const [failed, setFailed] = useState(false);
|
||||
const [baseline, setBaseline] = useState<BaselineView | null>(null);
|
||||
// Fixed per load, so the right-hand end of a chart is when it was read and does not creep as the page re-renders.
|
||||
const [to, setTo] = useState(() => Date.now());
|
||||
|
||||
@@ -52,11 +54,40 @@ export default function ServerTrends({ serverId }: { serverId: number }) {
|
||||
};
|
||||
}, [serverId, days]);
|
||||
|
||||
// What is usual for each hour of the week, loaded once; it only matters while the points are single samples or hours (the weekday means nothing for a day's average).
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
api.servers
|
||||
.baseline(serverId)
|
||||
.then((res) => alive && setBaseline(res))
|
||||
.catch(() => alive && setBaseline(null));
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [serverId]);
|
||||
|
||||
const from = to - days * 86_400_000;
|
||||
const rangeLabel = CHART_RANGES.find((r) => r.days === days)?.label ?? `${days} days`;
|
||||
const charts = useMemo(
|
||||
() => (series ?? []).map((s) => ({ s, words: describeTrend(s), series: [{ name: s.label, color: levelColor(s), points: s.points }] })),
|
||||
[series],
|
||||
() =>
|
||||
(series ?? []).map((s) => {
|
||||
const lines = [{ name: s.label, color: levelColor(s), points: s.points as { t: string; v: number; lo?: number; hi?: number }[] }];
|
||||
const slots = s.kind === "disk" || !baseline ? null : baseline.slots[s.kind];
|
||||
if (slots && days <= 30) {
|
||||
// The usual for the hour each point falls in, as a line with a band around it: the median and two spreads either side.
|
||||
const usual = s.points.flatMap((p) => {
|
||||
const h = hourOfWeek(Date.parse(p.t), baseline!.timezone);
|
||||
const slot = slots[h.dow * 24 + h.hour];
|
||||
if (!slot) return [];
|
||||
const room = 2 * Math.max(slot.spread, s.kind === "cpu" ? 4 : 2);
|
||||
return [{ t: p.t, v: slot.median, lo: Math.max(0, slot.median - room), hi: Math.min(100, slot.median + room) }];
|
||||
});
|
||||
if (usual.length > 0) lines.push({ name: "Usual for the time", color: "#868e96", points: usual });
|
||||
}
|
||||
const here = s.kind === "disk" || !baseline ? null : baseline.slots[s.kind][baseline.now.dow * 24 + baseline.now.hour];
|
||||
return { s, words: describeTrend(s), series: lines, usualNow: here };
|
||||
}),
|
||||
[series, baseline, days],
|
||||
);
|
||||
|
||||
return (
|
||||
@@ -76,16 +107,22 @@ export default function ServerTrends({ serverId }: { serverId: number }) {
|
||||
</div>
|
||||
) : (
|
||||
<div className="trend-grid">
|
||||
{charts.map(({ s, words, series: lines }) => (
|
||||
{charts.map(({ s, words, series: lines, usualNow }) => (
|
||||
<div key={s.metric} className="trend-block mb-3">
|
||||
<div className="d-flex flex-wrap align-items-baseline gap-2 mb-1">
|
||||
<strong>{s.label}</strong>
|
||||
<span>{s.latest !== null ? `${Math.round(s.latest)}%` : "—"}</span>
|
||||
<span className="text-secondary small">{words}</span>
|
||||
{usualNow && (
|
||||
<span className="text-secondary small" title={`The median of this hour of the week over ${usualNow.weeks} weeks`}>
|
||||
· usually about {Math.round(usualNow.median)}% now
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<TimeChart series={lines} from={from} to={to} compact label={`${s.label} over the last ${rangeLabel}, ${s.latest !== null ? `${Math.round(s.latest)}% now` : "no reading"}`} />
|
||||
</div>
|
||||
))}
|
||||
{charts.some((c) => c.series.length > 1) && <div className="text-secondary small">The grey band is what is usual for that hour of the week, from this server’s own history (the median, two spreads either side).</div>}
|
||||
{days > 35 && <div className="text-secondary small">Over {days > 120 ? "more than four months" : "more than five weeks"} each point is {days > 120 ? "a day" : "an hour"}’s average, and the shaded band is its lowest and highest.</div>}
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user