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"; import PageIntro from "../components/PageIntro"; import FigureHistory from "../components/FigureHistory"; import { t } from "../i18n"; /** 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 {t("Off")}; if (!p.state) return {t("Not read yet")}; if (!p.fresh) return Can’t be read; if (p.problems.some((x) => x.severity === "critical")) return {t("Needs a look")}; if (p.problems.length > 0) return {t("Needs a look")}; return {t("In order")}; } 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 (

{p.name}

{p.status ? <>read : "not read yet"}
{p.status && !p.status.ok &&
The last attempt to read it failed: {p.status.error ?? "no answer"}.
} {p.problems.length > 0 && ( )} {s && ( <>
{[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(" · ")}

{t("Targets by job")}

{!s.jobs ? (
{t("Prometheus did not answer about its targets.")}
) : s.jobs.length === 0 ? (
{t("None.")}
) : (
{s.jobs.map((j) => ( ))}
{t("Job")} {t("Up")} {t("Down")}
{j.job} {j.up} 0 ? "text-red fw-bold" : "text-secondary"}`}>{j.down}
)} {s.down && s.down.length > 0 && ( <>

{t("Not answering")}

)}

{t("Alerts firing")}

{!s.alerts ? (
{t("Prometheus did not answer about its alerts.")}
) : firing.length === 0 ? (
None{pending.length > 0 ? ` (${pending.length} pending)` : ""}.
) : ( )} )}
); } /** 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(null); const [error, setError] = useState(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 ( <>

Prometheus

What Prometheus already measures, in the same list as everything else. It is read every couple of minutes (see {t("Integrations")}). A target that has not answered for five minutes and an alert that Prometheus’s rules are firing are alerts — see {t("Alerts")}. Alerts that Grafana manages itself are not seen. {!data && !error && } {data && data.length === 0 && (
)} {data?.map((p) => )} ); }