Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to deal with first label in metric #756

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading