使用微創(chuàng)聯(lián)合M5S空氣檢測(cè)儀、樹莓派3b+、prometheus、grafana實(shí)現(xiàn)空氣質(zhì)量持續(xù)監(jiān)控告警WEB可視化

1.簡(jiǎn)介

使用微創(chuàng)聯(lián)合M5S空氣檢測(cè)儀、樹莓派3b+、prometheus、grafana實(shí)現(xiàn)空氣質(zhì)量持續(xù)監(jiān)控告警WEB可視化

grafana dashboard效果:

image-20201031171328947

2.背景

2.1 需求:

1.過(guò)段時(shí)間公司要搬新辦公室,較多同事?lián)募兹?HCHO)、異味(TVOC)這些重要的空氣指標(biāo),所以需要能夠?qū)ζ錂z測(cè)

2.能夠把這些空氣指標(biāo)進(jìn)行WEB展示

3.監(jiān)控告警關(guān)心的空氣指,告警發(fā)送到釘釘群

2.2 已有硬件:

樹莓派3b+ (長(zhǎng)期吃灰中)以下簡(jiǎn)稱樹莓派

微創(chuàng)聯(lián)合M5S空氣檢測(cè)儀(版本:M5S溫濕+鋰電+TVOC+數(shù)據(jù)導(dǎo)出 17年485元價(jià)格購(gòu)買 )以下簡(jiǎn)稱空氣檢測(cè)儀

M5S 家用 激光PM2.5檢測(cè)儀 甲醛 CO2 空氣質(zhì)量 霧霾甲醛 檢測(cè)儀

【在售價(jià)】380.00 元(基礎(chǔ)版)

【立即下單】點(diǎn)擊鏈接立即下單:https://s.click.taobao.com/zREU4vu

img

3.設(shè)計(jì)

把空氣檢測(cè)儀的usb插到樹莓派上(樹莓派上通過(guò)串口讀取數(shù)據(jù)),供電也是通過(guò)樹莓派供電

相關(guān)軟件運(yùn)行在樹莓派上

3.1 硬件:

空氣檢測(cè)儀如何導(dǎo)出數(shù)據(jù)?

空氣檢測(cè)儀是有數(shù)據(jù)導(dǎo)出版本,自帶串口轉(zhuǎn)USB(ch340芯片)

打開空氣檢測(cè)儀并通過(guò)檢測(cè)儀左側(cè) FUN 按鈕,把屏幕切換到第 3 屏,這個(gè)時(shí)候串口中就會(huì)持續(xù)輸出監(jiān)控?cái)?shù)據(jù)

在linux上設(shè)備文件符為“/dev/ttyUSB0”

cat /dev/ttyUSB0
#可以看到
24.9 45.2 23 32 35 26 33 35 4419 1301 159 8 3 0 0.006 0.21

讀取過(guò)程中,按一下檢測(cè)儀上的 RST 鍵,可以顯示每列數(shù)據(jù)對(duì)應(yīng)的字段定義,(按完后需要再按 FUN 鍵切換到第 3 屏

*--------------------------------------- Data Output Format Definition ----------------------------------------*
TEMP HUMI CH_PM1.0 CH_PM2.5 CH_PM10 US_PM1.0 US_PM2.5 US_PM10 >0.3um >0.5um >1.0um >2.5um >5.0um >10um HCHO TVOC
TEMP HUMI CH_PM1.0 CH_PM2.5 CH_PM10 US_PM1.0 US_PM2.5 US_PM10 >0.3um >0.5um >1.0um >2.5um >5.0um >10um HCHO TVOC
25.1 43.3 21 29 31 22 29 31 3843 1136 170 6 2 0 0.003 0.2
25.1 43.2 22 30 31 23 30 31 3876 1156 170 5 2 0 0.005 0.16
25.1 43.3 22 30 31 23 30 31 3963 1174 164 6 2 0 0.003 0.21
25.2 43.3 22 30 31 23 30 31 3942 1163 167 6 2 0 0.007 0.21

帶二氧化碳檢測(cè)的版本在HCHO字段前多一個(gè)CO2字段

更多資料看空氣檢測(cè)儀配套的資料

3.2 軟件:

軟件監(jiān)控采用prometheus + grafana的方案

本文為流水理魚wwek原創(chuàng) www.iamle.com

現(xiàn)在只需要實(shí)現(xiàn)一個(gè)串口(/dev/ttyUSB0) exporter即可把空氣監(jiān)測(cè)儀的數(shù)據(jù)打通給prometheus使用

最后配置prometheus取空氣檢測(cè)儀的exporter數(shù)據(jù),并配置grafana面板

監(jiān)控告警直接使用grafana帶的監(jiān)控告警

4.實(shí)現(xiàn)

*安裝配置wclh_air_detector_exporter 獲得空氣檢測(cè)儀數(shù)據(jù)

wclh_air_detector_exporter讀取串口數(shù)據(jù)并把數(shù)據(jù)進(jìn)行結(jié)構(gòu)化,然后輸出metrics

M5S Temperature and Humidity+lithium battery+CO2+TVOC PM2.5 CO2(S8)TEMP&HUMI Detector Haze PM2.5 sensors Laser PM2.5 detector

M5S 家用 激光PM2.5檢測(cè)儀 甲醛 CO2 空氣質(zhì)量 霧霾甲醛 檢測(cè)儀

WCLH_AIR_DETECTOR_EXPORTER_VERSION=0.1.3
wget https://github.com/wwek/wclh_air_detector_exporter/releases/download/v${WCLH_AIR_DETECTOR_EXPORTER_VERSION}/wclh_air_detector_exporter_${WCLH_AIR_DETECTOR_EXPORTER_VERSION}_linux_armv7.tar.gz
tar zxvf wclh_air_detector_exporter_${WCLH_AIR_DETECTOR_EXPORTER_VERSION}_linux_armv7.tar.gz
mkdir -p /data/soft/wclh_air_detector_exporter
mv wclh_air_detector_exporter /data/soft/wclh_air_detector_exporter
cd /data/soft/wclh_air_detector_exporter

#./wclh_air_detector_exporter -serial_port /dev/ttyUSB0

#自動(dòng)啟動(dòng)&進(jìn)程守護(hù)
sudo bash -c 'cat > /etc/systemd/system/wclh_air_detector_exporter.service << EOF
[Unit]
Description=https://github.com/wwek/wclh_air_detector_exporter
Wants=network-online.target
After=network-online.target

[Service]
Restart=on-failure
#User=root
ExecStart=/data/soft/wclh_air_detector_exporter/wclh_air_detector_exporter

[Install]
WantedBy=default.target
EOF'

sudo systemctl daemon-reload
sudo systemctl status wclh_air_detector_exporter
sudo systemctl start wclh_air_detector_exporter
sudo systemctl enable wclh_air_detector_exporter
sudo systemctl status wclh_air_detector_exporter

curl http://localhost:9166/metrics

安裝配置prometheus

PROMETHEUS_VERSION=2.22.0
wget https://github.com/prometheus/prometheus/releases/download/v${PROMETHEUS_VERSION}/prometheus-${PROMETHEUS_VERSION}.linux-armv7.tar.gz
tar zxvf prometheus-${PROMETHEUS_VERSION}.linux-armv7.tar.gz
mkdir -p /data/soft/
mv prometheus-${PROMETHEUS_VERSION}.linux-armv7 prometheus && mv prometheus /data/soft/

#自動(dòng)啟動(dòng)&進(jìn)程守護(hù)
sudo bash -c 'cat > /etc/systemd/system/prometheus.service << EOF
[Unit]
Description=https://prometheus.io
Wants=network-online.target
After=network-online.target

[Service]
Restart=on-failure
#User=root
ExecStart=/data/soft/prometheus/prometheus --config.file="/data/soft/prometheus/prometheus.yml"

[Install]
WantedBy=default.target
EOF'

sudo systemctl daemon-reload
sudo systemctl status prometheus
sudo systemctl start prometheus
sudo systemctl enable prometheus
sudo systemctl status prometheus

curl http://localhost:9090
#<a href="/graph">Found</a>.


安裝配置grafana

sudo apt-get install -y apt-transport-https
sudo apt-get install -y software-properties-common wget
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list 
sudo apt-get update
sudo apt-get install grafana
sudo systemctl daemon-reload
sudo systemctl start grafana-server
sudo systemctl enable grafana-server
sudo systemctl status grafana-server

curl http://localhost:3000
#<a href="/login">Found</a>.

grafana 中先配置 prometheus(http://localhost:9090)數(shù)據(jù)源,然后導(dǎo)入 “grafana-dashboard.json”空氣檢測(cè)儀的dashboard

監(jiān)控告警

直接使用grafana自帶的告警功能,將關(guān)心的指標(biāo)進(jìn)行監(jiān)控并告警
本文首發(fā)于流水理魚博客,如要轉(zhuǎn)載請(qǐng)注明出處。
歡迎關(guān)注我的公眾號(hào):流水理魚(liushuiliyu),全棧、云原生、Homelab交流。
如果您對(duì)相關(guān)文章感興趣,也可以關(guān)注我的博客:www.iamle.com 上面有更多內(nèi)容

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容