Created
January 17, 2021 21:18
-
-
Save leventyalcin/da96d3ebb4db2487274b254f584dfdb5 to your computer and use it in GitHub Desktop.
DHT data as Prometheus metrics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import Adafruit_DHT | |
from prometheus_client import start_http_server, Gauge | |
import time | |
import logging | |
import logging.handlers | |
logging.basicConfig(level=logging.NOTSET) | |
t = Gauge('temperature', 'Temperature', ['room', 'location']) | |
h = Gauge('humidity', 'Humidity', ['room', 'location']) | |
logging.info('Starting exporter daemon') | |
start_http_server(9000) | |
while True: | |
logging.info('Reading the sensor') | |
humidity, temperature = Adafruit_DHT.read_retry(11, 4) | |
t.labels(room='living', location='home').set(temperature) | |
h.labels(room='living', location='home').set(humidity) | |
time.sleep(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment