From f1085cda37fa197b367973d6eee17f682f00d301 Mon Sep 17 00:00:00 2001 From: Maaike Date: Fri, 30 Aug 2024 13:25:32 +0200 Subject: [PATCH] to deal with first label in metric (#756) --- wis2box-mqtt-metrics-collector/mqtt_metrics_collector.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/wis2box-mqtt-metrics-collector/mqtt_metrics_collector.py b/wis2box-mqtt-metrics-collector/mqtt_metrics_collector.py index f1d7ebb9..e57c2b5c 100644 --- a/wis2box-mqtt-metrics-collector/mqtt_metrics_collector.py +++ b/wis2box-mqtt-metrics-collector/mqtt_metrics_collector.py @@ -29,6 +29,7 @@ import sys import json +import time from prometheus_client import start_http_server, Counter, Gauge @@ -166,6 +167,13 @@ def sub_mqtt_metrics(client, userdata, msg): wsi = 'none' if 'wigos_station_identifier' in m['properties']: wsi = m['properties']['wigos_station_identifier'] + # if label wsi is not in notify_wsi_total, set to 0 and sleep 5s + if wsi not in notify_wsi_total._metrics: + logger.info(f"new station: {wsi}, sleep 5s before incrementing") + notify_wsi_total.labels(wsi).inc(0) + failure_wsi_total.labels(wsi).inc(0) + station_wsi.labels(wsi).set(1) + time.sleep(5) notify_wsi_total.labels(wsi).inc(1) failure_wsi_total.labels(wsi).inc(0) station_wsi.labels(wsi).set(1)