A year of history, one chart, and a read API with personal tokens
History: server load, memory and disks are also kept as hourly (four months) and daily (over two years) averages with lowest and highest; endpoint answers as hourly (four months) beside the daily figures. Charts ask for 24 hours to a year and are drawn from whichever is fine enough. A disk that two weeks call flat is looked at again over ninety days for the forecast. Built once from what is kept. One chart: TimeChart replaces the sparkline and the multi-line chart: hover and arrow-key readout, a lowest/highest band, gaps shown as gaps, the same ranges everywhere and the choice remembered. Used for server trends, comparing servers, a check's availability and answer times (Endpoints > History) and a server's availability. Read API: /api/v1 (servers, metrics, alerts, incidents, inventory, network, endpoints and their history, maintenance) with personal read-only tokens made under the user menu: shown once, hashed, 30/90/365 days or none, ten at most, removed with their owner. GET only. Documented in API.md. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5e26e77340
commit
68b41b5586
47 files changed
+12360
-247
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import { useCallback, useState } from "react";
|
||||
|
||||
/** The stretches of time every chart can show, the same everywhere: a day to a year. */
|
||||
export const CHART_RANGES = [
|
||||
{ days: 1, label: "24 hours" },
|
||||
{ days: 7, label: "7 days" },
|
||||
{ days: 30, label: "30 days" },
|
||||
{ days: 90, label: "90 days" },
|
||||
{ days: 365, label: "1 year" },
|
||||
] as const;
|
||||
|
||||
export type ChartDays = (typeof CHART_RANGES)[number]["days"];
|
||||
|
||||
const KEY = "chart.range";
|
||||
|
||||
const isRange = (n: number): n is ChartDays => CHART_RANGES.some((r) => r.days === n);
|
||||
|
||||
function remembered(fallback: ChartDays): ChartDays {
|
||||
try {
|
||||
const n = Number(localStorage.getItem(KEY));
|
||||
return isRange(n) ? n : fallback;
|
||||
} catch {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The range a chart shows, remembered between charts and visits: choosing 30 days on one page means the next chart opens on 30 days as well. A convenience only —
|
||||
* without storage it is just the default each time.
|
||||
*/
|
||||
export function useChartRange(fallback: ChartDays = 7): [ChartDays, (days: number) => void] {
|
||||
const [days, setDays] = useState<ChartDays>(() => remembered(fallback));
|
||||
const choose = useCallback((n: number) => {
|
||||
if (!isRange(n)) return;
|
||||
setDays(n);
|
||||
try {
|
||||
localStorage.setItem(KEY, String(n));
|
||||
} catch {
|
||||
// not remembered
|
||||
}
|
||||
}, []);
|
||||
return [days, choose];
|
||||
}
|
||||
Reference in new issue
Block a user