The DHT22 is a cheap "DIY" sensor for microcontrollers (arduino, rpi)
This repository creates a prometheus exporter so that metrics can be collected and displayed.
View above dashboard json here.
...
# HELP dht22_temperature_celsius Temperature in celsius provided by dht sensor
# TYPE dht22_temperature_celsius gauge
dht22_temperature_celsius 22.8
# HELP dht22_temperature_fahrenheit Temperature in fahrenheit provided by dht sensor
# TYPE dht22_temperature_fahrenheit gauge
dht22_temperature_fahrenheit 73.0
# HELP dht22_humidity Humidity in percents provided by dht sensor
# TYPE dht22_humidity gauge
dht22_humidity 48.8
- Raspberry pi 3
- DHT22 Sensor
- The one linked above comes with built in resistor
- Copy the python file to the path you want to keep it. ex:
/usr/local/bin
- Go to that path and install dependencies:
sudo pip3 install -r requirements.txt
- Assuming the use of systemd, copy the service file at dht22-exporter.service to /etc/systemd/system and daemon-reload systemd via
sudo systemctl daemon-reload
. You might want to also enable the service so that it persists after a reboot:sudo systemctl enable dht22-exporter.service
. - In this service file some default values for the pin and polling rate
Ex: ./dht22_exporter -g 4 -i 2
, change these values to align with what ever your board setup is. - If you're not running systemd, figure out a way to run the python file continuously (through screen, as a service, etc).
- Start the dht22-exporter service and point prometheus on port 8001 (unless changed with parameter
-p/--port
).
- The sensor sometimes gives wildly inaccurate readings (5000% humidity), this should be mitigated by some checks in the code, but ~1% of sensor readings may not be even close to accurate.
- Clint Edwards - Github