About 1,600 more headings, buttons, table columns, status words, placeholders and short messages are translated. Tables of words built when the app loads are now read when they are drawn, so they follow the language, and a test fails if text is translated at load time. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
160 lines
7.3 KiB
TypeScript
160 lines
7.3 KiB
TypeScript
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 <span className="badge bg-secondary-lt text-secondary">{t("Off")}</span>;
|
|
if (!p.state) return <span className="badge bg-secondary-lt text-secondary">{t("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">{t("Needs a look")}</span>;
|
|
if (p.problems.length > 0) return <span className="badge bg-yellow-lt text-yellow">{t("Needs a look")}</span>;
|
|
return <span className="badge bg-green-lt text-green">{t("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>{t("Targets by job")}</h4>
|
|
{!s.jobs ? (
|
|
<div className="text-secondary mb-3">{t("Prometheus did not answer about its targets.")}</div>
|
|
) : s.jobs.length === 0 ? (
|
|
<div className="text-secondary mb-3">{t("None.")}</div>
|
|
) : (
|
|
<div className="table-responsive mb-3">
|
|
<table className="table table-vcenter table-sm">
|
|
<thead>
|
|
<tr>
|
|
<th>{t("Job")}</th>
|
|
<th className="text-end">{t("Up")}</th>
|
|
<th className="text-end">{t("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>{t("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>{t("Alerts firing")}</h4>
|
|
{!s.alerts ? (
|
|
<div className="text-secondary mb-3">{t("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>
|
|
)}
|
|
</>
|
|
)}
|
|
<FigureHistory integrationId={p.id} name={p.name} />
|
|
</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>
|
|
<PageIntro>
|
|
What Prometheus already measures, in the same list as everything else. It is read every couple of minutes (see <Link to="/integrations">{t("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">{t("Alerts")}</Link>. Alerts that Grafana manages itself are not seen.
|
|
</PageIntro>
|
|
<ErrorNotice error={error} />
|
|
{!data && !error && <BlockSkeleton lines={4} />}
|
|
{data && data.length === 0 && (
|
|
<div className="card">
|
|
<div className="card-body">
|
|
<EmptyState title={t("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} />)}
|
|
</>
|
|
);
|
|
}
|