Files
homepage/src/widgets/prometheus/component.jsx
shamoon eda06965fa
Some checks are pending
Docker CI / Linting Checks (push) Waiting to run
Docker CI / Docker Build & Push (push) Blocked by required conditions
Chore: add organize imports to pre-commit (#5104)
2025-03-30 21:40:03 -07:00

39 lines
1.3 KiB
JavaScript

import Block from "components/services/widget/block";
import Container from "components/services/widget/container";
import { useTranslation } from "next-i18next";
import useWidgetAPI from "utils/proxy/use-widget-api";
export default function Component({ service }) {
const { t } = useTranslation();
const { widget } = service;
const { data: targetsData, error: targetsError } = useWidgetAPI(widget, "targets");
if (targetsError) {
return <Container service={service} error={targetsError} />;
}
if (!targetsData) {
return (
<Container service={service}>
<Block label="prometheus.targets_up" />
<Block label="prometheus.targets_down" />
<Block label="prometheus.targets_total" />
</Container>
);
}
const upCount = targetsData.data.activeTargets.filter((a) => a.health === "up").length;
const downCount = targetsData.data.activeTargets.filter((a) => a.health === "down").length;
const totalCount = targetsData.data.activeTargets.length;
return (
<Container service={service}>
<Block label="prometheus.targets_up" value={t("common.number", { value: upCount })} />
<Block label="prometheus.targets_down" value={t("common.number", { value: downCount })} />
<Block label="prometheus.targets_total" value={t("common.number", { value: totalCount })} />
</Container>
);
}