From e8131c322ec1d8bd7de11df7961a1dd9268e94f4 Mon Sep 17 00:00:00 2001
From: Sheogorath <sheogorath@shivering-isles.com>
Date: Sun, 23 Oct 2022 01:31:29 +0200
Subject: [PATCH] fix(iot): Fix multiple Gauges showing up in Grafana

Since each of the shelly-ht-action pods have their name and IP address
attached to the metrics collected from them, it will result in multiple
metrics existing as `last_over_time`. As a result multiple of the gauges
will show up, and things start to look silly.

This patch fixes the problem by putting an average over all values that
exist in parallel, by that dropping the instance and pod labels and
therefore result in only one metric that is displayed as intended.
---
 apps/base/iot/dashboards/room.json | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/apps/base/iot/dashboards/room.json b/apps/base/iot/dashboards/room.json
index ef695823c..55c0f651c 100644
--- a/apps/base/iot/dashboards/room.json
+++ b/apps/base/iot/dashboards/room.json
@@ -148,7 +148,7 @@
             "uid": ""
           },
           "editorMode": "code",
-          "expr": "last_over_time(shellyht_humidity_percent{name=\"$sensor\"}[24h])",
+          "expr": "avg(last_over_time(shellyht_humidity_percent{name=\"$sensor\"}[24h])) by (name)",
           "legendFormat": "__auto",
           "range": true,
           "refId": "A"
@@ -218,7 +218,7 @@
             "uid": ""
           },
           "editorMode": "code",
-          "expr": "last_over_time(shellyht_temperature_celsius{name=\"$sensor\"}[24h])",
+          "expr": "avg(last_over_time(shellyht_temperature_celsius{name=\"$sensor\"}[24h])) by (name)",
           "legendFormat": "__auto",
           "range": true,
           "refId": "A"
@@ -344,7 +344,7 @@
             "uid": ""
           },
           "editorMode": "code",
-          "expr": "last_over_time(shellyht_temperature_celsius{name=\"$sensor\"}[24h])",
+          "expr": "avg(last_over_time(shellyht_temperature_celsius{name=\"$sensor\"}[24h])) by (name)",
           "legendFormat": "Temperature",
           "range": true,
           "refId": "A"
@@ -355,7 +355,7 @@
             "uid": ""
           },
           "editorMode": "code",
-          "expr": "last_over_time(shellyht_humidity_percent{name=\"$sensor\"}[24h])",
+          "expr": "avg(last_over_time(shellyht_humidity_percent{name=\"$sensor\"}[24h])) by (name)",
           "hide": false,
           "legendFormat": "Humidity",
           "range": true,
@@ -478,7 +478,7 @@
           },
           "editorMode": "code",
           "exemplar": false,
-          "expr": "last_over_time(shellyht_humidity_percent[24h])",
+          "expr": "avg(last_over_time(shellyht_humidity_percent[24h])) by (name)",
           "instant": false,
           "interval": "",
           "legendFormat": "{{name}}",
@@ -577,7 +577,7 @@
             "uid": ""
           },
           "editorMode": "code",
-          "expr": "last_over_time(shellyht_temperature_celsius[24h])",
+          "expr": "avg(last_over_time(shellyht_temperature_celsius[24h])) by (name)",
           "legendFormat": "{{name}}",
           "range": true,
           "refId": "A"
-- 
GitLab