
这个的目的是采集树莓派的数据并在仪表盘展示,需要用到如下几个工具:
1、树莓派4,这个不用说了。
2、Grafana是一个golang开发的可视化工具。
3、Telegraf是一个专门收集数据的工具。可以从堆栈、传感器和系统中收集数据。
4、InfluxDB是一个时序数据库。
安装设置自启动并启动
curl -sL https://packages.grafana.com/gpg.key | sudo apt-key add -
curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
echo "deb https://repos.influxdata.com/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt update
sudo apt install -y grafana influxdb telegraf influxdb-client
sudo systemctl enable influxdb grafana-server telegraf
sudo systemctl start influxdb grafana-server telegraf
安装好之后服务分别运行在如下端口:
Grafana :3000 (默认帐号 admin admin)
InfluxDB:8086
influxdb配置
输入influx
create database rpi
use rpi
create user grafana with password 'grafana' with all privileges
grant all privileges on rpi to grafana
show users
user admin
grafana true
Telegraf 配置
sudo nano /etc/telegraf/telegraf.conf
加入这些内容
[[outputs.influxdb]]
urls = ["http://127.0.0.1:8086"]
database ="rpi"
username= "grafana"
password="grafana"
加入CPU和GPU的配置
sudo nano /etc/telegraf/telegraf.d/raspberrypi.conf
把下面配置加进去。
[[inputs.net]]
[[inputs.netstat]]
[[inputs.file]]
files = ["/sys/class/thermal/thermal_zone0/temp"]
name_override = "cpu_temperature"
data_format = "value"
data_type = "integer"
[[inputs.exec]]
commands = ["/opt/vc/bin/vcgencmd measure_temp"]
name_override = "gpu_temperature"
data_format = "grok"
grok_patterns = ["%{NUMBER:value:float}"]
测试配置
pi@raspberrypi:/etc/telegraf $ telegraf --test --config /etc/telegraf/telegraf.d/raspberrypi.conf
2021-12-12T08:21:22Z I! Starting Telegraf 1.20.4
(...)
cpu_temperature,host=raspberrypi value=53154i 1594658607000000000
gpu_temperature,host=raspberrypi value=53.7 1594658607000000000
重启加载配置
pi@raspberrypi:~ $ sudo systemctl reload telegraf.service
调试配置
telegraf -debug -config telegraf.conf
配置Grafana,增加lnfluxdb为数据源
Log in to your Grafana instance and head to “Data Sources”. Select “Add new Data Source” and find InfluxDB under “Timeseries Databases”.
登录到Grafana中,点击数据源,选择增加新的数据源,找到Timeseries Databases下面的InfluxDB。
主机名:localhost:8086
数据库:rpi
用户名:grafana
密码:grafana
增加仪表盘
返回到Grafana前端,增加第一个仪表盘。鼠标点击“+”(在住页面搜索的下面),选择 导入(import),然后输入 ID 10578,并加载。
参考链接 :https://grafana.com/grafana/dashboards/10578
成功收工。

如果 出现问题
dpkg: error processing archive /var/cache/apt/archives/influxdb_1.8.10-1_armhf.deb (--unpack):
trying to overwrite '/usr/bin/influx', which is also in package influxdb-client 1.6.7~rc0-1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
/var/cache/apt/archives/influxdb_1.8.10-1_armhf.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
请使用如下代码
sudo dpkg -P influxdb-client
sudo dpkg -i sudo dpkg -i /var/cache/apt/archives/influxdb_1.8.10-1_armhf.deb