Prometheus, Immich and Paperless-ngx integrations
Three read-only integrations, each with a monitoring page, alerts, maintenance silencing and held-when-unreadable handling. Prometheus: scrape targets that stop answering (5 minutes, one alert per job) and alerts that Prometheus's own rules fire (critical when labelled so). Immich: disk under the library filling, failed background jobs, counts. Paperless-ngx: worker/database/Redis in error, documents that failed to import, index and sanity check, disk. Immich and Paperless also in /metrics. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
aebe98bf15
commit
251a4a9d73
47 files changed
+24148
-7
No files matched your search
@@ -0,0 +1,155 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type PrometheusInfo } from "../api/client";
|
||||
import EmptyState from "../components/EmptyState";
|
||||
import TimeAgo from "../components/TimeAgo";
|
||||
import { BlockSkeleton } from "../components/Skeleton";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
import { readableError } from "../utils/errors";
|
||||
|
||||
/** Alerts every pipeline carries to prove it works: they are always firing, so they are not shown as firing. */
|
||||
const BY_DESIGN = /^(watchdog|deadmansswitch|deadmanssnitch|infoinhibitor)$/i;
|
||||
|
||||
function Badge({ p }: { p: PrometheusInfo }) {
|
||||
if (!p.enabled) return <span className="badge bg-secondary-lt text-secondary">Off</span>;
|
||||
if (!p.state) return <span className="badge bg-secondary-lt text-secondary">Not read yet</span>;
|
||||
if (!p.fresh) return <span className="badge bg-yellow-lt text-yellow">Can’t be read</span>;
|
||||
if (p.problems.some((x) => x.severity === "critical")) return <span className="badge bg-red-lt text-red">Needs a look</span>;
|
||||
if (p.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 Card({ p }: { p: PrometheusInfo }) {
|
||||
const s = p.state;
|
||||
const targets = s?.jobs ? s.jobs.reduce((n, j) => n + j.up + j.down, 0) : null;
|
||||
const down = s?.jobs ? s.jobs.reduce((n, j) => n + j.down, 0) : null;
|
||||
const firing = s?.alerts?.filter((a) => a.state === "firing" && !BY_DESIGN.test(a.name)) ?? [];
|
||||
const pending = s?.alerts?.filter((a) => a.state === "pending") ?? [];
|
||||
return (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">
|
||||
{p.name} <Badge p={p} />
|
||||
</h3>
|
||||
<div className="card-actions text-secondary small">{p.status ? <>read <TimeAgo value={p.status.at} /></> : "not read yet"}</div>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
{p.status && !p.status.ok && <div className="text-yellow mb-2">The last attempt to read it failed: {p.status.error ?? "no answer"}.</div>}
|
||||
{p.problems.length > 0 && (
|
||||
<ul className="mb-3">
|
||||
{p.problems.map((x) => (
|
||||
<li key={x.key} className={x.severity === "critical" ? "text-red" : ""}>
|
||||
{x.message}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
{s && (
|
||||
<>
|
||||
<div className="text-secondary small mb-3">
|
||||
{[s.version ? `version ${s.version}` : null, targets === null ? "targets could not be read" : `${targets} target${targets === 1 ? "" : "s"}, ${down} down`, s.alerts === null ? "alerts could not be read" : `${firing.length} alert${firing.length === 1 ? "" : "s"} firing`].filter(Boolean).join(" · ")}
|
||||
</div>
|
||||
|
||||
<h4>Targets by job</h4>
|
||||
{!s.jobs ? (
|
||||
<div className="text-secondary mb-3">Prometheus did not answer about its targets.</div>
|
||||
) : s.jobs.length === 0 ? (
|
||||
<div className="text-secondary mb-3">None.</div>
|
||||
) : (
|
||||
<div className="table-responsive mb-3">
|
||||
<table className="table table-vcenter table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Job</th>
|
||||
<th className="text-end">Up</th>
|
||||
<th className="text-end">Down</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{s.jobs.map((j) => (
|
||||
<tr key={j.job}>
|
||||
<td>{j.job}</td>
|
||||
<td className="text-end">{j.up}</td>
|
||||
<td className={`text-end ${j.down > 0 ? "text-red fw-bold" : "text-secondary"}`}>{j.down}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{s.down && s.down.length > 0 && (
|
||||
<>
|
||||
<h4>Not answering</h4>
|
||||
<ul className="mb-3">
|
||||
{s.down.map((d) => (
|
||||
<li key={`${d.job}-${d.instance}`}>
|
||||
<strong>{d.instance}</strong> <span className="text-secondary">({d.job}) since <TimeAgo value={d.since} /></span>
|
||||
{d.error && <div className="text-secondary small">{d.error}</div>}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</>
|
||||
)}
|
||||
|
||||
<h4>Alerts firing</h4>
|
||||
{!s.alerts ? (
|
||||
<div className="text-secondary mb-3">Prometheus did not answer about its alerts.</div>
|
||||
) : firing.length === 0 ? (
|
||||
<div className="text-secondary mb-3">None{pending.length > 0 ? ` (${pending.length} pending)` : ""}.</div>
|
||||
) : (
|
||||
<ul className="mb-3">
|
||||
{firing.map((a, i) => (
|
||||
<li key={`${a.name}-${a.instance}-${i}`} className={a.severity === "critical" ? "text-red" : ""}>
|
||||
<strong>{a.name}</strong>
|
||||
{a.severity && <span className="text-secondary"> ({a.severity})</span>}
|
||||
{a.instance && <span className="text-secondary"> on {a.instance}</span>}
|
||||
{a.summary && <div className="text-secondary small">{a.summary}</div>}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Prometheus: whether the targets it scrapes are answering and which of its alerts are firing — what you already measure, in the same list as everything else. */
|
||||
export default function Prometheus() {
|
||||
const [data, setData] = useState<PrometheusInfo[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
useEffect(() => {
|
||||
const load = () =>
|
||||
api.prometheus
|
||||
.list()
|
||||
.then((r) => {
|
||||
setData(r.prometheuses);
|
||||
setError(null);
|
||||
})
|
||||
.catch((err) => setError(readableError(err)));
|
||||
void load();
|
||||
const t = setInterval(load, 30_000);
|
||||
return () => clearInterval(t);
|
||||
}, []);
|
||||
return (
|
||||
<>
|
||||
<h2 className="page-title">Prometheus</h2>
|
||||
<p className="text-secondary">
|
||||
What Prometheus already measures, in the same list as everything else. It is read every couple of minutes (see <Link to="/integrations">Integrations</Link>). A <strong>target that has not answered for five minutes</strong> and an <strong>alert that Prometheus’s rules are firing</strong> are
|
||||
alerts — see <Link to="/alerts">Alerts</Link>. Alerts that Grafana manages itself are not seen.
|
||||
</p>
|
||||
<ErrorNotice error={error} />
|
||||
{!data && !error && <BlockSkeleton lines={4} />}
|
||||
{data && data.length === 0 && (
|
||||
<div className="card">
|
||||
<div className="card-body">
|
||||
<EmptyState title="No Prometheus connected" hint="Add one under Integrations with its address (http://host:9090)." />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{data?.map((p) => <Card key={p.id} p={p} />)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user