From 8dcb3a27bdd602364a5867fb6fa50342d1d3e430 Mon Sep 17 00:00:00 2001 From: Tristin Terry Date: Fri, 24 Feb 2023 19:55:13 -0600 Subject: [PATCH 1/2] add prometheus service widget --- public/locales/en/common.json | 5 ++++ src/widgets/components.js | 1 + src/widgets/prometheus/component.jsx | 38 ++++++++++++++++++++++++++++ src/widgets/prometheus/widget.js | 14 ++++++++++ src/widgets/widgets.js | 2 ++ 5 files changed, 60 insertions(+) create mode 100644 src/widgets/prometheus/component.jsx create mode 100644 src/widgets/prometheus/widget.js diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 6bb3377e6..5b3608b69 100755 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -521,5 +521,10 @@ "pterodactyl": { "servers": "Servers", "nodes": "Nodes" + }, + "prometheus": { + "targets_up": "Targets Up", + "targets_down": "Targets Down", + "targets_total": "Total Targets" } } diff --git a/src/widgets/components.js b/src/widgets/components.js index 28a70755c..f8d766ce0 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -75,6 +75,7 @@ const components = { xteve: dynamic(() => import("./xteve/component")), immich: dynamic(() => import("./immich/component")), uptimekuma: dynamic(() => import("./uptimekuma/component")), + prometheus: dynamic(() => import("./prometheus/component")), }; export default components; diff --git a/src/widgets/prometheus/component.jsx b/src/widgets/prometheus/component.jsx new file mode 100644 index 000000000..f8cea560c --- /dev/null +++ b/src/widgets/prometheus/component.jsx @@ -0,0 +1,38 @@ +import { useTranslation } from "next-i18next"; + +import Container from "components/services/widget/container"; +import Block from "components/services/widget/block"; +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 ; + } + + if (!targetsData) { + return ( + + + + + + ); + } + + 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 ( + + + + + + ); +} diff --git a/src/widgets/prometheus/widget.js b/src/widgets/prometheus/widget.js new file mode 100644 index 000000000..2d442e493 --- /dev/null +++ b/src/widgets/prometheus/widget.js @@ -0,0 +1,14 @@ +import genericProxyHandler from "utils/proxy/handlers/generic"; + +const widget = { + api: "{url}/api/v1/{endpoint}", + proxyHandler: genericProxyHandler, + + mappings: { + targets: { + endpoint: "targets" + }, + }, +}; + +export default widget; \ No newline at end of file diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index 5d4b74a23..716257737 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -69,6 +69,7 @@ import xteve from "./xteve/widget"; import immich from "./immich/widget"; import uptimekuma from "./uptimekuma/widget"; import unmanic from "./unmanic/widget"; +import prometheus from "./prometheus/widget"; const widgets = { adguard, @@ -144,6 +145,7 @@ const widgets = { xteve, immich, uptimekuma, + prometheus }; export default widgets; From fe494a4ab3bef74ac913ae789e7aa87eb098d606 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 24 Feb 2023 22:07:42 -0800 Subject: [PATCH 2/2] add prometheus widget data validation --- src/widgets/prometheus/widget.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/widgets/prometheus/widget.js b/src/widgets/prometheus/widget.js index 2d442e493..40754477f 100644 --- a/src/widgets/prometheus/widget.js +++ b/src/widgets/prometheus/widget.js @@ -6,7 +6,10 @@ const widget = { mappings: { targets: { - endpoint: "targets" + endpoint: "targets", + validate: [ + "data" + ] }, }, };