Changeset - d35c626db59d
[Not reviewed]
default
0 1 0
Dennis Fink - 5 years ago 2020-02-10 21:09:27
dennis.fink@c3l.lu
Added power consumption handling
1 file changed with 11 insertions and 0 deletions:
0 comments (0 inline, 0 general)
mqtt2prometheus.py
Show inline comments
 
@@ -36,6 +36,9 @@ barometer = Gauge(
 
    "barometer_hectopascal", "The current air pressure", labelnames=["location"]
 
)
 

	
 
power_consumption = Gauge(
 
    "power_consumption_watt", "The current power used", labelnames=["location"]
 
)
 

	
 
def on_connect(client, userdata, flags, rc):
 
    client.publish("availability/mqtt2prometheus", "online", 2, True)
 
@@ -47,6 +50,7 @@ def on_connect(client, userdata, flags, 
 
    client.message_callback_add("sensors/temperature/#", handle_temperature)
 
    client.message_callback_add("sensors/humidity/#", handle_humidity)
 
    client.message_callback_add("sensors/barometer/#", handle_barometer)
 
    client.message_callback_add("sensors/power_consumption/#", handle_power_consumption)
 

	
 
    client.subscribe("sensors/people_now_present")
 
    client.subscribe("space/status")
 
@@ -56,6 +60,7 @@ def on_connect(client, userdata, flags, 
 
    client.subscribe("sensors/temperature/#")
 
    client.subscribe("sensors/humidity/#")
 
    client.subscribe("sensors/barometer/#")
 
    client.subscribe("sensors/power_consumption/#")
 

	
 

	
 
def handle_people_now_present(client, userdata, msg):
 
@@ -101,6 +106,12 @@ def handle_barometer(client, userdata, m
 
    barometer.labels(location).set(float(msg.payload))
 

	
 

	
 
def handle_power_consumption(client, userdata, msg):
 
    t = msg.topic.split("/")
 
    location = "-".join(t[2:])
 
    power_consumption.labels(location).set(float(msg.payload))
 

	
 

	
 
def main():
 

	
 
    client = mqtt.Client("mqtt2prometheus")
0 comments (0 inline, 0 general)