ラズパイにCO2センサー mh_z19 で二酸化炭素を測定し、node-exporter でデータ取得し、prometheusでグラフ化する。
rootで作業
sudo su -
raspi-config
3 Interface Options
I1 SSH Enable/disable remote command line access using SSH
I2 VNC Enable/disable graphical remote desktop access
I3 SPI Enable/disable automatic loading of SPI kernel module
I4 I2C Enable/disable automatic loading of I2C kernel module
☆I5 Serial Port Enable/disable shell messages on the serial connection
I6 1-Wire Enable/disable one-wire interface
I7 Remote GPIO Enable/disable remote access to GPIO pins
Would you like a login shell to be accessible over serial? で「いいえ」を選択する Would you like the serial port hardware to be enabled? で「はい」を選択する
reboot
sudo su -
apt update
apt upgrade
apt install python3-pip
pip3 install --break-system-packages --user mh_z19
python -m mh_z19
root@raspberrypi:~# python -m mh_z19
{"co2": 593}
root@raspberrypi:~#
root@raspberrypi:~# python -m mh_z19 --all
{"co2": 402, "temperature": 26, "TT": 66, "SS": 0, "UhUl": 13568}
root@raspberrypi:~#
apt install prometheus-node-exporter-collectors
ls -l /var/lib/prometheus/node-exporter/
chmod 755 collect-co2.sh
./collect-co2.sh
ls -l /var/lib/prometheus/node-exporter/
cat /var/lib/prometheus/node-exporter/mh_z19.prom
出力例
mh_z19_co2 713
mh_z19_co2_retry 0
crontab -e
追加する
### raspi-co2-exporter ###
* * * * * /root/collect-co2.sh
- job_name: node
# If prometheus-node-exporter is installed, grab stats about the local
# machine by default.
static_configs:
- targets:
- localhost:9100
- 192.168.0.50:9100 ★