Changeset - 2847b90c29c0
[Not reviewed]
default
0 1 0
Dennis Fink - 6 years ago 2019-12-27 17:57:48
dennis.fink@c3l.lu
Added handling of temperature
1 file changed with 11 insertions and 0 deletions:
0 comments (0 inline, 0 general)
mqtt2prometheus.py
Show inline comments
 
@@ -26,6 +26,9 @@ availability = Gauge(
 
    labelnames=["clientname"],
 
)
 

	
 
temperature = Gauge(
 
    "temperature_celsius", "The current temperature", labelnames=["location"]
 
)
 

	
 

	
 
def on_connect(client, userdata, flags, rc):
 
@@ -35,12 +38,14 @@ def on_connect(client, userdata, flags, 
 
    client.message_callback_add("space/status", handle_space_status)
 
    client.message_callback_add("space/member_count", handle_member_count)
 
    client.message_callback_add("availability/#", handle_availability)
 
    client.message_callback_add("sensors/temperature/#", handle_temperature)
 

	
 
    client.subscribe("sensors/people_now_present")
 
    client.subscribe("space/status")
 
    client.subscribe("space/member_count")
 
    client.subscribe("availability/+")
 
    client.subscribe("availability/shutdown/+")
 
    client.subscribe("sensors/temperature/#")
 

	
 

	
 
def handle_people_now_present(client, userdata, msg):
 
@@ -68,6 +73,12 @@ def handle_availability(client, userdata
 
    availability.labels(c).set(v)
 

	
 

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

	
 

	
 
def main():
 

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