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,78 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { api, type UptimeReport } from "../api/client";
|
||||
import RangeSelect from "./RangeSelect";
|
||||
import TimeChart from "./TimeChart";
|
||||
import { BlockSkeleton } from "./Skeleton";
|
||||
import { useChartRange } from "../utils/chartRanges";
|
||||
|
||||
const DAY_MS = 24 * 3600_000;
|
||||
/** A day of uptime is drawn green when nothing was wrong, amber for some time down, red for most of the day. */
|
||||
const dayColor = (v: number) => (v >= 99.9 ? "#2fb344" : v >= 50 ? "#f59f00" : "#f03e3e");
|
||||
|
||||
/**
|
||||
* How a server (or an integration) has done, a day at a time, as far back as the record goes: the share of each day it was up. The thin ribbon on the lists is the
|
||||
* last 30 days of the same thing; this is the chart, with a value for any day and a range up to a year.
|
||||
*/
|
||||
export default function UptimeHistory({ kind, id, name }: { kind: "servers" | "integrations"; id: number; name: string }) {
|
||||
const [chosen, setDays] = useChartRange(30);
|
||||
// A day is the smallest thing recorded, so 24 hours is not offered here: a chart of a single bar says nothing.
|
||||
const days = chosen < 30 ? 30 : chosen;
|
||||
const [report, setReport] = useState<UptimeReport | null>(null);
|
||||
const [failed, setFailed] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
setFailed(false);
|
||||
api.uptime
|
||||
.get(days)
|
||||
.then((res) => alive && setReport(res))
|
||||
.catch(() => alive && setFailed(true));
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [days]);
|
||||
|
||||
const series = report?.[kind][id];
|
||||
const to = report ? Date.parse(report.endsAt) : Date.now();
|
||||
const lines = useMemo(() => {
|
||||
if (!report || !series) return [];
|
||||
const end = Date.parse(report.endsAt);
|
||||
return [
|
||||
{
|
||||
name: "Up",
|
||||
color: "#2fb344",
|
||||
// One point per day with something known about it, in the middle of that day.
|
||||
points: series.buckets.flatMap((b, i) => (b.k === 0 ? [] : [{ t: new Date(end - (report.days - i - 0.5) * DAY_MS).toISOString(), v: Math.round((1 - b.d / b.k) * 1000) / 10 }])),
|
||||
},
|
||||
];
|
||||
}, [report, series]);
|
||||
|
||||
return (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header d-flex flex-wrap gap-2">
|
||||
<h3 className="card-title me-auto">Availability</h3>
|
||||
<RangeSelect value={days} onChange={setDays} only={[30, 90, 365]} />
|
||||
</div>
|
||||
<div className="card-body">
|
||||
{failed ? (
|
||||
<div className="text-secondary">Couldn't load the record.</div>
|
||||
) : !report ? (
|
||||
<BlockSkeleton lines={3} />
|
||||
) : !series ? (
|
||||
<div className="text-secondary">Nothing is known about {name} in this stretch yet.</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="mb-2">
|
||||
<span className="h3 me-2">{series.percent}%</span>
|
||||
<span className="text-secondary">up over the last {days} days</span>
|
||||
</div>
|
||||
<TimeChart series={lines} from={to - days * DAY_MS} to={to} bars barColor={dayColor} label={`${name}: share of each day it was up, over the last ${days} days. ${series.percent}% in all.`} />
|
||||
<div className="text-secondary small mt-2">
|
||||
Worked out from when it stopped reporting and reported again, so it goes back as far as the change log does; days before it was known are left blank.
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user