Services: opt-in monitoring with a per-server watch list

A failed service now raises an alert (and counts in /metrics and the public API) only when the server is told to watch it, by name or pattern, or * for all. Failed services that are not watched still show on the Host health card with a Watch button. Replaces the ignore list.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-11-16 21:48:32 +01:00
1 parent 6e39430a1f
commit 06ac120a1d
19 files changed
+143 -121

No files matched your search

+3 -3
View File
@@ -840,7 +840,7 @@ export interface AgentLatest {
/** What a Linux agent says about the machine itself. Each part is there only if the agent could find it out. */
export interface HostHealth {
failedUnits?: { unit: string; description: string; /** This server is told to ignore it: it doesn't count as failed. */ ignored?: boolean }[];
failedUnits?: { unit: string; description: string; /** Whether this server is told to watch it: one that is not watched does not count as failed. */ watched?: boolean }[];
smart?: { device: string; model: string; healthy: boolean | null; temperatureC: number | null; wearPercent: number | null }[];
zfs?: { name: string; health: string; capacityPercent: number | null }[];
reportedAt: string;
@@ -863,8 +863,8 @@ export interface ServerThresholds {
diskForecastDays?: number;
backupStaleHours?: number;
mounts?: Record<string, { percent?: number; ignore?: boolean }>;
/** Services never to count as failed here: names or patterns like "gupdate*". */
ignoreServices?: string[];
/** The services to watch here: names or patterns like "docker*" ("*" is all). Only a watched service that has failed raises an alert. */
watchServices?: string[];
}
/** One thing worth telling a person about a server's agent: what it couldn't collect (and what to do), or that it is behind. */
+27 -30
View File
@@ -13,25 +13,25 @@ const poolFine = (health: string) => health.toUpperCase() === "ONLINE";
*/
export default function HostHealthCard({
health,
ignored = [],
onIgnoredChange,
watched = [],
onWatchedChange,
}: {
health: HostHealth | null;
/** The services this server is told to ignore (names or patterns). */
ignored?: string[];
/** The services this server is told to watch (names or patterns). Only these raise an alert when they fail. */
watched?: string[];
/** Given when the person can change that list; it is saved by whoever holds it. */
onIgnoredChange?: (list: string[]) => Promise<void> | void;
onWatchedChange?: (list: string[]) => Promise<void> | void;
}) {
const [pattern, setPattern] = useState("");
const [busy, setBusy] = useState(false);
if (!health && ignored.length === 0) return null;
if (!health && watched.length === 0) return null;
const { failedUnits, smart, zfs } = health ?? { failedUnits: undefined, smart: undefined, zfs: undefined, reportedAt: "" };
async function change(list: string[]) {
if (!onIgnoredChange) return;
if (!onWatchedChange) return;
setBusy(true);
try {
await onIgnoredChange(list);
await onWatchedChange(list);
setPattern("");
} finally {
setBusy(false);
@@ -39,7 +39,7 @@ export default function HostHealthCard({
}
const hasSmart = !!smart && smart.length > 0;
const hasZfs = !!zfs && zfs.length > 0;
if (failedUnits === undefined && !hasSmart && !hasZfs && ignored.length === 0) return null;
if (failedUnits === undefined && !hasSmart && !hasZfs && watched.length === 0) return null;
return (
<div className="card mb-3">
@@ -47,7 +47,7 @@ export default function HostHealthCard({
<h3 className="card-title">{t("Host health")}</h3>
{health?.reportedAt && (
<div className="card-actions text-secondary small">
reported <TimeAgo value={health.reportedAt} />
{t("reported")} <TimeAgo value={health.reportedAt} />
</div>
)}
</div>
@@ -55,19 +55,18 @@ export default function HostHealthCard({
{failedUnits !== undefined && (
<div className={hasSmart || hasZfs ? "mb-3" : ""}>
<div className="text-secondary small mb-1">{t("Services")}</div>
{failedUnits.filter((u) => !u.ignored).length === 0 ? (
<span className="badge bg-green-lt text-green">none have failed</span>
) : null}
{failedUnits.length === 0 ? <span className="badge bg-green-lt text-green">{t("none have failed")}</span> : null}
{failedUnits.length > 0 && failedUnits.every((u) => u.watched === false) && <div className="text-secondary small mb-1">{t("None of these is watched, so none raises an alert.")}</div>}
{failedUnits.length > 0 && (
<ul className="list-unstyled mb-0">
{failedUnits.map((u) => (
<li key={u.unit} className={u.ignored ? "text-secondary" : undefined}>
{u.ignored ? <span className="badge bg-secondary-lt text-secondary me-2">ignored</span> : <span className="badge bg-red-lt text-red me-2">failed</span>}
<li key={u.unit} className={u.watched === false ? "text-secondary" : undefined}>
{u.watched === false ? <span className="badge bg-secondary-lt text-secondary me-2">{t("not watched")}</span> : <span className="badge bg-red-lt text-red me-2">{t("failed")}</span>}
<code>{u.unit}</code>
{u.description && <span className="text-secondary small ms-2">{u.description}</span>}
{onIgnoredChange && !u.ignored && (
<button type="button" className="btn btn-link btn-sm p-0 ms-2 align-baseline" disabled={busy} title={t("Stop counting this service as failed on this server")} onClick={() => void change([...ignored, u.unit])}>
{t("Ignore")}
{onWatchedChange && u.watched === false && (
<button type="button" className="btn btn-link btn-sm p-0 ms-2 align-baseline" disabled={busy} title={t("Raise an alert when this service has failed on this server")} onClick={() => void change([...watched, u.unit])}>
{t("Watch")}
</button>
)}
</li>
@@ -77,32 +76,30 @@ export default function HostHealthCard({
</div>
)}
{(ignored.length > 0 || onIgnoredChange) && (
{(watched.length > 0 || onWatchedChange) && (
<div className={hasSmart || hasZfs ? "mb-3" : ""}>
<div className="text-secondary small mb-1">{t("Services this server ignores")}</div>
{ignored.length === 0 && <div className="text-secondary small mb-1">None. A service that always fails here (an updater, say) can be ignored, so it stops raising an alert.</div>}
<div className="text-secondary small mb-1">{t("Services to watch")}</div>
{watched.length === 0 && <div className="text-secondary small mb-1">{t("None. A service raises an alert only when it is listed here and has failed. Use * to watch them all.")}</div>}
<div className="d-flex flex-wrap gap-2 mb-1">
{ignored.map((p) => (
<span key={p} className="badge bg-secondary-lt text-secondary d-inline-flex align-items-center gap-1">
{watched.map((p) => (
<span key={p} className="badge bg-blue-lt text-blue d-inline-flex align-items-center gap-1">
<code>{p}</code>
{onIgnoredChange && (
<button type="button" className="btn-close btn-close-sm" style={{ fontSize: "0.5rem" }} aria-label={`Stop ignoring ${p}`} disabled={busy} onClick={() => void change(ignored.filter((x) => x !== p))} />
)}
{onWatchedChange && <button type="button" className="btn-close btn-close-sm" style={{ fontSize: "0.5rem" }} aria-label={`${t("Stop watching")} ${p}`} disabled={busy} onClick={() => void change(watched.filter((x) => x !== p))} />}
</span>
))}
</div>
{onIgnoredChange && (
{onWatchedChange && (
<form
className="d-flex gap-2"
onSubmit={(e) => {
e.preventDefault();
const p = pattern.trim();
if (p && !ignored.includes(p)) void change([...ignored, p]);
if (p && !watched.includes(p)) void change([...watched, p]);
}}
>
<input className="form-control form-control-sm" style={{ maxWidth: "18rem" }} aria-label={t("A service name or pattern to ignore")} placeholder="a name, or a pattern like gupdate*" maxLength={100} value={pattern} onChange={(e) => setPattern(e.target.value)} />
<input className="form-control form-control-sm" style={{ maxWidth: "18rem" }} aria-label={t("A service name or pattern to watch")} placeholder={t("a name, or a pattern like docker*")} maxLength={100} value={pattern} onChange={(e) => setPattern(e.target.value)} />
<button type="submit" className="btn btn-sm" disabled={busy || pattern.trim() === ""}>
{t("Ignore")}
{t("Watch")}
</button>
</form>
)}
+3 -3
View File
@@ -14,7 +14,7 @@ const FIELDS: { key: Field; label: string; unit: string; min: number; max: numbe
{ key: "backupStaleHours", get label() { return t("Its backup is too old after"); }, unit: "hours", min: 0, max: 2160, hint: "For the Proxmox guest this server is. 0 means it is never called stale.", onlyForGuests: true },
];
const has = (t: Thresholds | null) => !!t && (Object.keys(t).some((k) => k !== "mounts" && k !== "ignoreServices") || Object.keys(t.mounts ?? {}).length > 0);
const has = (t: Thresholds | null) => !!t && (Object.keys(t).some((k) => k !== "mounts" && k !== "watchServices") || Object.keys(t.mounts ?? {}).length > 0);
/**
* This server's own alert limits. Anything left empty follows Settings → Notifications, so changing the global limit still reaches every
@@ -55,7 +55,7 @@ export default function ServerThresholds({ server, defaults, disks, canEdit, onC
}
if (Object.keys(rules).length > 0) out.mounts = rules;
// The services to ignore are edited on the health card; saving limits here must not lose them.
if (own?.ignoreServices?.length) out.ignoreServices = own.ignoreServices;
if (own?.watchServices?.length) out.watchServices = own.watchServices;
return Object.keys(out).length > 0 ? out : null;
}
@@ -198,7 +198,7 @@ export default function ServerThresholds({ server, defaults, disks, canEdit, onC
{busy ? "Saving…" : t("Save")}
</button>
{has(own) && (
<button type="button" className="btn" disabled={busy} onClick={() => void save(own?.ignoreServices?.length ? { ignoreServices: own.ignoreServices } : null)}>
<button type="button" className="btn" disabled={busy} onClick={() => void save(own?.watchServices?.length ? { watchServices: own.watchServices } : null)}>
{t("Follow Settings again")}
</button>
)}
+12
View File
@@ -84,6 +84,7 @@ export const sv: Record<string, string> = {
"A job to add": "Ett jobb att lägga till",
"A month": "En månad",
"A name like Europe/Stockholm, so 02:00 stays 02:00 in summer and winter.": "Ett namn som Europe/Stockholm, så att 02:00 förblir 02:00 sommar som vinter.",
"a name, or a pattern like docker*": "ett namn, eller ett mönster som docker*",
"A page to open (optional)": "En sida att öppna (valfritt)",
"A plan updates a group of servers on a schedule, one at a time, and stops if one fails. Tag the servers (for example “lab”), then make a plan for that tag.": "En plan uppdaterar en grupp servrar enligt schema, en i taget, och stannar om en misslyckas. Tagga servrarna (till exempel ”lab”) och skapa sedan en plan för taggen.",
"A playbook that only restarts the server, in the same Semaphore. It runs once a server's updates are in; a server with nothing waiting that still says a restart is due is restarted too. Each restart is checked: the server must report that it started again. The window below counts for the update and the restart together.": "En playbook som bara startar om servern, i samma Semaphore. Den körs när en servers uppdateringar är installerade; en server utan väntande uppdateringar som ändå säger att en omstart behövs startas också om. Varje omstart kontrolleras: servern måste rapportera att den startade om. Fönstret nedan gäller för uppdateringen och omstarten tillsammans.",
@@ -94,6 +95,7 @@ export const sv: Record<string, string> = {
"A scan from this app connected to it": "En skanning från den här appen kopplade upp sig mot den",
"A server": "En server",
"A service name or pattern to ignore": "Ett tjänstenamn eller mönster att ignorera",
"A service name or pattern to watch": "Ett tjänstenamn eller mönster att bevaka",
"a week": "en vecka",
"About": "Gäller",
"About you": "Om dig",
@@ -683,6 +685,7 @@ export const sv: Record<string, string> = {
"Export CSV": "Exportera CSV",
"Exporting…": "Exporterar…",
"External port": "Extern port",
"failed": "fallerade",
"Failed": "Misslyckades",
"Failed in the last day": "Misslyckades det senaste dygnet",
"Failed to import": "Importen misslyckades",
@@ -1275,10 +1278,13 @@ export const sv: Record<string, string> = {
"None connected.": "Ingen ansluten.",
"None has been made.": "Ingen har gjorts.",
"None has been taken.": "Ingen har tagits.",
"none have failed": "ingen har fallerat",
"None of these is watched, so none raises an alert.": "Ingen av dessa bevakas, så ingen ger larm.",
"None to choose from": "Inga att välja bland",
"None yet — add a picture of the rack or of a label.": "Inga ännu — lägg till en bild på racket eller på en etikett.",
"None yet.": "Inga ännu.",
"None.": "Inga.",
"None. A service raises an alert only when it is listed here and has failed. Use * to watch them all.": "Inga. En tjänst ger bara larm när den står här och har fallerat. Använd * för att bevaka alla.",
"Normal": "Normal",
"Not a VM? Hide this": "Ingen VM? Dölj det här",
"Not answering": "Svarar inte",
@@ -1308,6 +1314,7 @@ export const sv: Record<string, string> = {
"Not set up yet": "Inte uppsatt än",
"Not silenced": "Inte tystad",
"Not that": "Inte det",
"not watched": "bevakas inte",
"Not working": "Fungerar inte",
"Note": "Anteckning",
"Note (optional)": "Anteckning (valfri)",
@@ -1553,6 +1560,7 @@ export const sv: Record<string, string> = {
"Rack unit": "Rackenhet",
"Racks": "Rack",
"Raise alerts about it again": "Larma om den igen",
"Raise an alert when this service has failed on this server": "Larma när den här tjänsten har fallerat på den här servern",
"Raised": "Utlöst",
"Raised and cleared again and again within an hour — its messages are held back until it has been calm for an hour": "Larmat och släckts om och om igen inom en timme — dess meddelanden hålls tillbaka tills det har varit lugnt i en timme",
"Raised and cleared often enough within an hour to count as flapping": "Larmat och släckts tillräckligt ofta inom en timme för att räknas som fladdrande",
@@ -1633,6 +1641,7 @@ export const sv: Record<string, string> = {
"Replace names somebody wrote": "Ersätt namn som någon skrivit",
"Replace this list": "Ersätt den här listan",
"Replacement": "Ersättning",
"reported": "rapporterat",
"Reported": "Rapporterad",
"Reported by the agent as of": "Rapporterat av agenten per",
"Reporting": "Rapporterar",
@@ -1834,6 +1843,7 @@ export const sv: Record<string, string> = {
"Service levels": "Servicenivåer",
"Services": "Tjänster",
"Services this server ignores": "Tjänster som den här servern ignorerar",
"Services to watch": "Tjänster att bevaka",
"Sessions": "Sessioner",
"Set a target": "Sätt ett mål",
"Set elsewhere": "Satt någon annanstans",
@@ -1962,6 +1972,7 @@ export const sv: Record<string, string> = {
"Stop tracking": "Sluta spåra",
"Stop tracking domain": "Sluta spåra domän",
"Stop warning alerts": "Sluta ge varningslarm",
"Stop watching": "Sluta bevaka",
"Stopped": "Stoppad",
"stopped being followed": "följs inte längre",
"stopping": "stoppar",
@@ -2268,6 +2279,7 @@ export const sv: Record<string, string> = {
"Watch": "Bevaka",
"Watch again": "Bevaka igen",
"Watch something": "Bevaka något",
"Watched. It raises an alert if it fails on this server.": "Bevakas. Den ger larm om den slutar fungera på den här servern.",
"Watching": "Bevakar",
"Web address": "Webbadress",
"Webhook delivered successfully.": "Webhooken levererades.",
+4 -4
View File
@@ -826,14 +826,14 @@ export default function ServerDetail({ user }: { user: CurrentUser }) {
<>
<HostHealthCard
health={server.hostHealth}
ignored={server.thresholds?.ignoreServices ?? []}
onIgnoredChange={
watched={server.thresholds?.watchServices ?? []}
onWatchedChange={
isAdmin
? async (list) => {
try {
// The list is part of the server's own limits; the rest of them are carried over as they are.
await api.servers.update(server.id, { thresholds: { ...(server.thresholds ?? {}), ignoreServices: list.length > 0 ? list : undefined } });
toast.success(list.length > (server.thresholds?.ignoreServices?.length ?? 0) ? "Ignored. It no longer counts as failed on this server." : "Saved.");
await api.servers.update(server.id, { thresholds: { ...(server.thresholds ?? {}), watchServices: list.length > 0 ? list : undefined } });
toast.success(list.length > (server.thresholds?.watchServices?.length ?? 0) ? t("Watched. It raises an alert if it fails on this server.") : t("Saved."));
void loadDetail();
} catch (err) {
toast.error(readableError(err));