Skip to content

Commit

Permalink
to deal with first label in metric
Browse files Browse the repository at this point in the history
  • Loading branch information
maaikelimper committed Aug 30, 2024
1 parent 9827ce7 commit 89fe9d7
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 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,12 @@ 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 present in notify_wsi_total, set it to 0 and sleep 5 seconds before incrementing
if wsi not in notify_wsi_total._metrics:
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 89fe9d7

Please sign in to comment.