Changeset - d2da7d83904c
[Not reviewed]
default
0 1 0
Dennis Fink - 5 years ago 2020-02-10 22:41:20
dennis.fink@c3l.lu
Use try clause around setting values
1 file changed with 24 insertions and 6 deletions:
0 comments (0 inline, 0 general)
mqtt2prometheus.py
Show inline comments
 
@@ -103,37 +103,55 @@ def handle_availability(client, userdata
 
def handle_temperature(client, userdata, msg):
 
    t = msg.topic.split("/")
 
    location = "-".join(t[2:])
 
    temperature.labels(location).set(float(msg.payload))
 
    try:
 
        temperature.labels(location).set(float(msg.payload))
 
    except:
 
        pass
 

	
 

	
 
def handle_humidity(client, userdata, msg):
 
    t = msg.topic.split("/")
 
    location = "-".join(t[2:])
 
    humidity.labels(location).set(float(msg.payload))
 
    try:
 
        humidity.labels(location).set(float(msg.payload))
 
    except:
 
        pass
 

	
 

	
 
def handle_barometer(client, userdata, msg):
 
    t = msg.topic.split("/")
 
    location = "-".join(t[2:])
 
    barometer.labels(location).set(float(msg.payload))
 
    try:
 
        barometer.labels(location).set(float(msg.payload))
 
    except:
 
        pass
 

	
 

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

	
 

	
 
def handle_co2_emission(client, userdata, msg):
 
    t = msg.topic.split("/")
 
    location = "-".join(t[2:])
 
    co2_emission.labels(location).set(float(msg.payload))
 
    try:
 
        co2_emission.labels(location).set(float(msg.payload))
 
    except:
 
        pass
 

	
 

	
 
def handle_energy_consumption(client, userdata, msg):
 
    t = msg.topic.split("/")
 
    location = "-".join(t[2:])
 
    energy_consumption.labels(location).set(float(msg.payload))
 
    try:
 
        energy_consumption.labels(location).set(float(msg.payload))
 
    except:
 
        pass
 

	
 

	
 
def main():
0 comments (0 inline, 0 general)