AdGuard Home, Grafana, Docker image age, foldable server page cards

New integration kinds adguard (status, statistics, filter lists and a real DNS question
over UDP; alerts for DNS down/not running, protection left off, stale lists) and grafana
(alert rules firing or failing, data-source health). Optional warning for running Docker
images built more than N days ago (off by default). A server's overview cards can be
folded and arranged, kept per user. Migrations 0075-0077; docs, metrics and tests included.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-27 22:13:03 +01:00
1 parent 3d9a2310bb
commit 551eb1597a
53 files changed
+27700 -33

No files matched your search

+179
View File
@@ -0,0 +1,179 @@
import { useEffect, useState } from "react";
import { Link } from "react-router-dom";
import { api, type AdguardInstance } from "../api/client";
import EmptyState from "../components/EmptyState";
import TimeAgo from "../components/TimeAgo";
import { BlockSkeleton } from "../components/Skeleton";
import { ErrorNotice } from "../components/Notice";
import { formatAgo } from "../utils/duration";
import { readableError } from "../utils/errors";
function Badge({ a }: { a: AdguardInstance }) {
if (!a.enabled) return <span className="badge bg-secondary-lt text-secondary">Off</span>;
if (!a.state) return <span className="badge bg-secondary-lt text-secondary">Not read yet</span>;
if (!a.fresh) return <span className="badge bg-yellow-lt text-yellow">Can&rsquo;t be read</span>;
if (a.problems.some((x) => x.severity === "critical")) return <span className="badge bg-red-lt text-red">Needs a look</span>;
if (a.problems.length > 0) return <span className="badge bg-yellow-lt text-yellow">Needs a look</span>;
return <span className="badge bg-green-lt text-green">In order</span>;
}
function Tile({ label, value, sub, tone }: { label: string; value: string; sub?: string | null; tone?: "bad" | "warn" }) {
return (
<div className="col-6 col-lg-3">
<div className="card card-sm h-100">
<div className="card-body">
<div className="text-secondary small">{label}</div>
<div className={`h2 mb-0 ${tone === "bad" ? "text-red" : tone === "warn" ? "text-yellow" : ""}`}>{value}</div>
{sub && <div className="text-secondary small">{sub}</div>}
</div>
</div>
</div>
);
}
function Counted({ title, items, empty }: { title: string; items: { name: string; count: number }[]; empty: string }) {
const top = items[0]?.count ?? 0;
return (
<div className="col-lg-4">
<h4>{title}</h4>
{items.length === 0 && <div className="text-secondary small">{empty}</div>}
{items.slice(0, 7).map((i) => (
<div key={i.name} className="mb-1">
<div className="d-flex small">
<span className="text-break">{i.name}</span>
<span className="ms-auto text-secondary ps-2">{i.count.toLocaleString()}</span>
</div>
<div className="progress progress-sm">
<div className="progress-bar" style={{ width: `${top > 0 ? Math.max(2, (i.count / top) * 100) : 0}%` }} />
</div>
</div>
))}
</div>
);
}
function Card({ a }: { a: AdguardInstance }) {
const s = a.state;
const st = s?.stats ?? null;
const lists = s?.filters?.lists ?? [];
const on = lists.filter((l) => l.enabled);
const oldest = on.map((l) => l.updated).filter((u): u is string => u !== null).sort()[0] ?? null;
return (
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">
{a.name} <span className="text-secondary fw-normal">{s?.version ?? ""}</span> <Badge a={a} />
</h3>
<div className="card-actions text-secondary small">{a.status ? <>read <TimeAgo value={a.status.at} /></> : "not read yet"}</div>
</div>
<div className="card-body">
{a.status && !a.status.ok && <div className="text-yellow mb-2">The last attempt to read it failed: {a.status.error ?? "no answer"}.</div>}
{a.problems.length > 0 && (
<ul className="mb-3">
{a.problems.map((x) => (
<li key={x.key} className={x.severity === "critical" ? "text-red" : ""}>
{x.message}
</li>
))}
</ul>
)}
{s && (
<>
<div className="row g-3 mb-3">
<Tile
label="DNS answers"
value={!s.running ? "Not running" : s.probe === null ? "—" : s.probe.ok ? `${s.probe.ms ?? "?"} ms` : "No"}
sub={s.probe ? (s.probe.ok ? `a question about ${s.probe.name}, asked ${s.probe.host}:${s.dnsPort}` : `${s.probe.error ?? "no answer"} (${s.probe.host}:${s.dnsPort})`) : "no test yet"}
tone={!s.running || (s.probe && !s.probe.ok) ? "bad" : undefined}
/>
<Tile label="Protection" value={s.protectionEnabled ? "On" : "Off"} sub={s.protectionEnabled ? null : s.protectionOffSince ? `since ${formatAgo(s.protectionOffSince)} — nothing is being blocked` : "nothing is being blocked"} tone={s.protectionEnabled ? undefined : "warn"} />
<Tile label={`Queries${st?.periodHours ? `, last ${st.periodHours >= 48 ? `${Math.round(st.periodHours / 24)} days` : `${st.periodHours} h`}` : ""}`} value={st ? st.queries.toLocaleString() : "—"} sub={st && st.avgMs !== null ? `${st.avgMs} ms on average` : st ? null : "could not be read"} />
<Tile label="Blocked" value={st ? st.blocked.toLocaleString() : "—"} sub={st ? (st.blockedPercent === null ? null : `${st.blockedPercent}% of the queries`) : "could not be read"} />
</div>
{st && (st.topBlocked.length > 0 || st.topClients.length > 0 || st.topQueried.length > 0) && (
<div className="row g-3 mb-3">
<Counted title="Blocked most" items={st.topBlocked} empty="Nothing blocked." />
<Counted title="Asked about most" items={st.topQueried} empty="No queries." />
<Counted title="Asking most" items={st.topClients} empty="No clients." />
</div>
)}
<h4>Filter lists</h4>
{s.filters === null ? (
<div className="text-secondary small">They could not be read.</div>
) : (
<>
<div className="text-secondary small mb-2">
Filtering is {s.filters.enabled ? "on" : "off"}; {on.length} of {lists.length} lists switched on
{oldest ? (
<>
, the longest since an update <TimeAgo value={oldest} />
</>
) : (
""
)}
.
</div>
{s.staleLists.length > 0 && <div className="text-yellow small mb-2">Not updated for over a week: {s.staleLists.join(", ")}.</div>}
<ul className="small mb-0">
{lists.map((l) => (
<li key={l.name} className={l.enabled ? "" : "text-secondary"}>
{l.name} {!l.enabled && <span className="badge bg-secondary-lt text-secondary">off</span>}{" "}
<span className="text-secondary">
{l.rules !== null ? `${l.rules.toLocaleString()} rules · ` : ""}
{l.updated ? (
<>
updated <TimeAgo value={l.updated} />
</>
) : (
"never updated"
)}
</span>
</li>
))}
</ul>
</>
)}
</>
)}
</div>
</div>
);
}
/** AdGuard Home: whether DNS really answers, whether it protects, what it has done and whether its lists are kept up to date. */
export default function AdguardHome() {
const [data, setData] = useState<AdguardInstance[] | null>(null);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
const load = () =>
api.adguard
.list()
.then((r) => {
setData(r.instances);
setError(null);
})
.catch((err) => setError(readableError(err)));
void load();
const t = setInterval(load, 60_000);
return () => clearInterval(t);
}, []);
return (
<>
<h2 className="page-title">AdGuard Home</h2>
<p className="text-secondary">
Read every two minutes (see <Link to="/integrations">Integrations</Link>), with a real DNS question put to it each time — its web interface can be up while DNS is not. Nothing is changed. <strong>DNS that stops answering</strong>, <strong>a DNS server that is not running</strong>,{" "}
<strong>protection left off for an hour</strong> and <strong>filter lists that stopped updating</strong> are alerts — see <Link to="/alerts">Alerts</Link>.
</p>
<ErrorNotice error={error} />
{!data && !error && <BlockSkeleton lines={4} />}
{data && data.length === 0 && (
<div className="card">
<div className="card-body">
<EmptyState title="No AdGuard Home connected" hint="Add one under Integrations with its address and, if it has a sign-in, a user name and password." />
</div>
</div>
)}
{data?.map((a) => <Card key={a.id} a={a} />)}
</>
);
}