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
@@ -1,16 +1,13 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { Link, useSearchParams } from "react-router-dom";
|
||||
import { api, type ServerMetricSeries, type ServerRecord } from "../api/client";
|
||||
import MultiLineChart, { type ChartSeries } from "../components/MultiLineChart";
|
||||
import TimeChart, { type ChartSeries } from "../components/TimeChart";
|
||||
import RangeSelect from "../components/RangeSelect";
|
||||
import { CHART_RANGES, useChartRange } from "../utils/chartRanges";
|
||||
import { BlockSkeleton } from "../components/Skeleton";
|
||||
import ExportTableButton from "../components/ExportTableButton";
|
||||
|
||||
const MAX_SERVERS = 4;
|
||||
const RANGES = [
|
||||
{ days: 1, label: "24 hours" },
|
||||
{ days: 7, label: "7 days" },
|
||||
{ days: 30, label: "30 days" },
|
||||
];
|
||||
// A colour and a dash pattern for each line, so they can be told apart by either.
|
||||
const LOOKS = [
|
||||
{ color: "#4299e1", dash: "" },
|
||||
@@ -43,7 +40,7 @@ export default function ServerCompare() {
|
||||
return [...seen].slice(0, MAX_SERVERS);
|
||||
}, [params]);
|
||||
|
||||
const [days, setDays] = useState(7);
|
||||
const [days, setDays] = useChartRange(7);
|
||||
const [metric, setMetric] = useState("cpu");
|
||||
const [loaded, setLoaded] = useState<Loaded[] | null>(null);
|
||||
const [failed, setFailed] = useState(false);
|
||||
@@ -98,7 +95,7 @@ export default function ServerCompare() {
|
||||
};
|
||||
});
|
||||
const chart: ChartSeries[] = rows.filter((r) => r.series).map((r) => ({ name: r.server.name, color: r.look.color, dash: r.look.dash, points: r.series!.points }));
|
||||
const summary = `${metricName} over the last ${RANGES.find((r) => r.days === days)?.label}: ${rows.map((r) => `${r.server.name} ${percent(r.now)} now`).join(", ")}`;
|
||||
const summary = `${metricName} over the last ${CHART_RANGES.find((r) => r.days === days)?.label}: ${rows.map((r) => `${r.server.name} ${percent(r.now)} now`).join(", ")}`;
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -126,13 +123,7 @@ export default function ServerCompare() {
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select className="form-select form-select-sm w-auto" aria-label="Time range" value={days} onChange={(e) => setDays(Number(e.target.value))}>
|
||||
{RANGES.map((r) => (
|
||||
<option key={r.days} value={r.days}>
|
||||
Last {r.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<RangeSelect value={days} onChange={setDays} />
|
||||
<ExportTableButton filename={`compare-${metric}`} />
|
||||
</div>
|
||||
<div className="card-body">
|
||||
@@ -145,7 +136,7 @@ export default function ServerCompare() {
|
||||
{chart.length === 0 ? (
|
||||
<div className="text-secondary mb-3">None of these servers has a history for this yet. A sample is kept about every ten minutes once an agent has reported.</div>
|
||||
) : (
|
||||
<MultiLineChart series={chart} from={to - days * 86_400_000} to={to} label={summary} />
|
||||
<TimeChart series={chart} from={to - days * 86_400_000} to={to} label={summary} />
|
||||
)}
|
||||
<div className="table-responsive mt-3">
|
||||
<table className="table table-vcenter">
|
||||
|
||||
Reference in new issue
Block a user