Skip to content

Commit

Permalink
to deal with first label in metric (#756)
Browse files Browse the repository at this point in the history
  • Loading branch information
maaikelimper authored Aug 30, 2024
1 parent 9827ce7 commit f1085cd
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions wis2box-mqtt-metrics-collector/mqtt_metrics_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import sys
import json
import time

from prometheus_client import start_http_server, Counter, Gauge

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f1085cd

Please sign in to comment.