From 0f4b5f6039c99633d93fd76ed26ff191ce86bf84 Mon Sep 17 00:00:00 2001 From: Thomas Jensen Date: Thu, 30 Jan 2020 11:31:19 +0100 Subject: [PATCH] add support for static node descriptions --- exporter.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/exporter.py b/exporter.py index 4cb6610..9ad9599 100644 --- a/exporter.py +++ b/exporter.py @@ -10,6 +10,12 @@ topics = [ ("+/alert", 0), ("homelab/ats/supply/+", 0) ] +nodes = { + 'rack-temp': 'Office RPi temperature probes', + 'powerpi': 'Homelab RPi power monitoring', + 'hass': 'Home Assistant', + 'exporter': 'Prometheus MQTT topic exporter' + } node_api = NodeAPI() @@ -18,6 +24,12 @@ MQTT_BROKER_CLIENTS = Gauge('mqtt_broker_clients', 'MQTT broker clients connecte MQTT_ALERT = Gauge('mqtt_alert_state', 'MQTT alert topic states', ['origin', 'alert']) MQTT_STATUS = Gauge('mqtt_status', 'MQTT status topic', ['status']) +def get_desc(node): + if node in nodes: + return nodes[node] + else: + return node_api.get(node) + def on_log(client, userdata, level, buff): print(buff) @@ -39,7 +51,7 @@ def on_message(client, userdata, msg): topic = msg.topic.split('/') if topic[0] == "$CONNECTED": - MQTT_CONNECTED.labels(topic[1], node_api.get(topic[1])).set(int(msg.payload)) + MQTT_CONNECTED.labels(topic[1], get_desc(topic[1])).set(int(msg.payload)) elif msg.topic == "$SYS/broker/clients/connected": MQTT_BROKER_CLIENTS.set(int(msg.payload))