From 460983b74126fc5251b9dde5cf920607bf76dfec Mon Sep 17 00:00:00 2001
From: shamoon <4887959+shamoon@users.noreply.github.com>
Date: Mon, 13 Feb 2023 20:53:45 -0800
Subject: [PATCH] Add grafana stats
---
public/locales/en/common.json | 2 ++
src/widgets/grafana/component.jsx | 13 +++++++++----
src/widgets/grafana/widget.js | 6 ++++++
3 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/public/locales/en/common.json b/public/locales/en/common.json
index c902f91c..98f2b796 100644
--- a/public/locales/en/common.json
+++ b/public/locales/en/common.json
@@ -485,6 +485,8 @@
"time": "Time"
},
"grafana": {
+ "dashboards": "Dashboards",
+ "datasources": "Data Sources",
"totalalerts": "Total Alerts",
"alertstriggered": "Alerts Triggered"
}
diff --git a/src/widgets/grafana/component.jsx b/src/widgets/grafana/component.jsx
index 2d6520dd..98d4c42b 100755
--- a/src/widgets/grafana/component.jsx
+++ b/src/widgets/grafana/component.jsx
@@ -8,15 +8,18 @@ export default function Component({ service }) {
const { t } = useTranslation();
const { widget } = service;
+ const { data: statsData, error: statsError } = useWidgetAPI(widget, "stats");
const { data: alertsData, error: alertsError } = useWidgetAPI(widget, "alerts");
- if (alertsError) {
- return ;
+ if (statsError || alertsError) {
+ return ;
}
- if (!alertsData) {
+ if (!statsData || !alertsData) {
return (
+
+
@@ -25,7 +28,9 @@ export default function Component({ service }) {
return (
-
+
+
+
a.state === "alerting").length })} />
);
diff --git a/src/widgets/grafana/widget.js b/src/widgets/grafana/widget.js
index 6ab53db0..64051925 100755
--- a/src/widgets/grafana/widget.js
+++ b/src/widgets/grafana/widget.js
@@ -8,6 +8,12 @@ const widget = {
alerts: {
endpoint: "alerts",
},
+ stats: {
+ endpoint: "admin/stats",
+ validate: [
+ "dashboards"
+ ]
+ },
},
};