Disk fill forecasts, skeleton loaders, and a Silence button on alerts
A disk that is on course to be full within 14 days (setting: 0 turns it off) is flagged on the Alerts page and dashboard, from the server's own history: needs three days of steady growth, skips erratic disks and ones the ordinary disk alert covers. Skeleton placeholders replace "Fetching status…" and "Loading…". Alerts that a maintenance window can silence get a Silence button (1, 4 or 24 hours) that starts one, and the alert list is refreshed at once when a window starts or ends. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
82974b98d0
commit
f7f5e1cd41
24 files changed
+566
-25
No files matched your search
@@ -86,6 +86,10 @@ export function bucketPoints(points: { t: number; v: number }[], from: number, t
|
||||
export interface Trend {
|
||||
/** Change in the percentage per day, from a straight line through the points. */
|
||||
perDay: number;
|
||||
/** How well a straight line describes the points, 0 to 1 (R²). A steady climb is near 1; a single jump or a wobble is low. */
|
||||
fit: number;
|
||||
/** How much time the points cover, in days. */
|
||||
spanDays: number;
|
||||
/** For something that fills up: days until it reaches 100% at that rate. Null when it isn't rising or the rate is negligible. */
|
||||
daysToFull: number | null;
|
||||
}
|
||||
@@ -106,16 +110,49 @@ export function trendOf(points: { t: number; v: number }[]): Trend | null {
|
||||
const meanY = ys.reduce((a, b) => a + b, 0) / n;
|
||||
let num = 0;
|
||||
let den = 0;
|
||||
let totalVariance = 0;
|
||||
for (let i = 0; i < n; i++) {
|
||||
num += (xs[i] - meanX) * (ys[i] - meanY);
|
||||
den += (xs[i] - meanX) ** 2;
|
||||
totalVariance += (ys[i] - meanY) ** 2;
|
||||
}
|
||||
if (den === 0) return null;
|
||||
const slope = num / den;
|
||||
// R²: the share of the movement the straight line explains. A flat series has nothing to explain, so it is no "fit" at all.
|
||||
const fit = totalVariance === 0 ? 0 : Math.round(((num * num) / (den * totalVariance)) * 100) / 100;
|
||||
const perDay = Math.round(slope * 100) / 100;
|
||||
const last = ys[n - 1];
|
||||
const daysToFull = perDay >= 0.05 && last < 100 ? Math.ceil((100 - last) / perDay) : null;
|
||||
return { perDay, daysToFull };
|
||||
return { perDay, fit, spanDays: Math.round((span / DAY_MS) * 10) / 10, daysToFull };
|
||||
}
|
||||
|
||||
export interface DiskForecast {
|
||||
mount: string;
|
||||
latest: number;
|
||||
perDay: number;
|
||||
daysToFull: number;
|
||||
}
|
||||
|
||||
/** What a forecast needs before it is worth raising an alert about: enough history, and growth that really is steady. */
|
||||
export const FORECAST_MIN_SPAN_DAYS = 3;
|
||||
export const FORECAST_MIN_FIT = 0.9;
|
||||
|
||||
/**
|
||||
* The disks that are heading for full within `withinDays`. A disk already at or above `alreadyAlertedAt` percent is left out — the
|
||||
* ordinary "disk nearly full" alert covers it — and so is one whose growth is erratic (a big copy, a log that rotates), where a
|
||||
* straight-line forecast would just be a guess.
|
||||
*/
|
||||
export function disksFillingSoon(series: MetricSeries[], withinDays: number, alreadyAlertedAt: number): DiskForecast[] {
|
||||
const out: DiskForecast[] = [];
|
||||
for (const s of series) {
|
||||
if (s.kind !== "disk" || !s.trend || s.latest === null) continue;
|
||||
const { perDay, fit, spanDays, daysToFull } = s.trend;
|
||||
if (daysToFull === null || daysToFull > withinDays) continue;
|
||||
if (spanDays < FORECAST_MIN_SPAN_DAYS || fit < FORECAST_MIN_FIT) continue;
|
||||
if (s.latest >= alreadyAlertedAt) continue;
|
||||
out.push({ mount: s.metric.slice("disk:".length), latest: s.latest, perDay, daysToFull });
|
||||
}
|
||||
return out.sort((a, b) => a.daysToFull - b.daysToFull);
|
||||
}
|
||||
|
||||
export interface MetricSeries {
|
||||
|
||||
Reference in new issue
Block a user