- Python 93.7%
- Makefile 6.3%
| .gitignore | ||
| dht22_exporter.py | ||
| Makefile | ||
| poetry.lock | ||
| pyproject.toml | ||
| README.md | ||
dht22_exporter
A Prometheus exporter for DHT22 temperature and humidity sensors on Raspberry Pi and GPIO-capable Linux systems.
Reads DHT22 sensors connected to GPIO pins and exposes temperature, humidity, and read-statistics metrics via an HTTP endpoint for Prometheus to scrape.
Features
- Support for multiple DHT22 probes on different GPIO pins
- Statistical filtering of readings (outlier removal via standard deviation bounds)
- Automatic retry on transient sensor errors
- Configurable read intervals, sample sizes, and tolerance thresholds
Requirements
- Python 3.9+
- Raspberry Pi or Linux system with GPIO support
- DHT22 sensor(s) wired to GPIO pins
Installation
pip install dht22-exporter
Or with Poetry:
poetry install
Configuration
Create a JSON configuration file at /etc/dht22_exporter.json or ~/.config/dht22_exporter.json:
{
"name": "dht22-exporter",
"sleep_between_read": 1,
"max_ping_read_retry": 3,
"temp_tolerated_stdev": 1,
"humidity_tolerated_stdev": 2,
"probes": [
{
"gpio_pin": 4,
"name": "bedroom",
"probe_type": "room",
"location": "upstairs"
},
{
"gpio_pin": 17,
"name": "outside",
"probe_type": "outside",
"location": "north-wall"
}
],
"loop": {
"interval": 240
},
"prometheus": {
"port": 9100,
"namespace": ""
},
"logging": {
"level": "WARNING"
}
}
Configuration reference
| Parameter | Default | Description |
|---|---|---|
sleep_between_read |
1 |
Seconds between consecutive sensor reads |
max_ping_read_retry |
3 |
Max retries on transient sensor errors |
temp_tolerated_stdev |
1 |
Temperature std-dev tolerance (°C) |
humidity_tolerated_stdev |
2 |
Humidity std-dev tolerance (%) |
loop.interval |
240 |
Seconds between collection cycles |
prometheus.port |
9100 |
HTTP port for the metrics endpoint |
prometheus.namespace |
"" |
Prometheus metric namespace prefix |
logging.level |
"WARNING" |
Log level (DEBUG, INFO, WARNING, ERROR, FATAL) |
Each probe entry requires gpio_pin (int), name (str), probe_type (str), and location (str).
Usage
python dht22_exporter.py
Metrics are then available at http://<host>:9100/metrics.
Metrics
temps (Gauge)
Temperature in degrees Celsius.
Labels: name, type, location, probe, serial
humidity (Gauge)
Relative humidity in percent.
Labels: name, type, location, probe, serial
probe_read (Counter)
I/O statistics for sensor reads.
Labels: name, type, location, probe, serial, result
Result values: ok (successful read), ko (failed read), used (reading included in final measurement), ignored (reading filtered as outlier).
How it works
Each collection cycle (default 240 s):
- Collects 5 temperature/humidity samples per probe, sleeping 1 s between reads.
- Retries transient read failures up to
max_ping_read_retrytimes. - Removes outliers that exceed the configured standard deviation thresholds.
- Requires at least 3 valid samples to accept a reading.
- Reports the mean of the remaining samples, rounded to 2 decimal places.
Development
make lint # run all linters (pep8, black, pylint, mypy)
make build # clean, lint, and build
make publish # build and publish to PyPI