Files
Obsidian-Main/-21.01. Linux/架站/Grafana.md

91 lines
4.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 設定
`docker-compose.yml` 如下:
```yaml
version: "3"
services:
grafana:
image: grafana/grafana:latest
container_name: grafana
restart: always
user: "1000" # needs to be `id -u` // alternatively chown the grafana/data dir to 472:472
ports:
- "8081:3000" # expose for localhost
links:
- influxdb
volumes:
- ./data/grafana/data:/var/lib/grafana # data path
- ./data/grafana/provisioning:/etc/grafana/provisioning
- ./data/grafana/grafana.ini:/etc/grafana/grafana.ini
environment:
- GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-simple-json-datasource
influxdb:
image: influxdb
ports:
- "8082:8086"
volumes:
- ./data/influxdb/data:/var/lib/influxdb2
telegraf:
image: telegraf
user: telegraf:992 # Get 992 by `stat -c '%g' /var/run/docker.sock`, depend on system
depends_on:
- influxdb
links:
- influxdb
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./data/telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro
environment:
- HOST_PROC=/proc
- HOST_SYS=/sys
- HOST_ETC=/etc
```
檔案結構如下:
```
data\
grafana\
grafana.ini
telegraf\
telegraf.conf
docker-compose.yml
```
`data/grafana/grafana.ini``data/telegraf/telegraf.conf` 都是需要事先準備好的檔案。
## 設定 InfluxDB
先把 docker 建立起來,然後打開 influxdb[http://awinpi4:8082](http://awinpi4:8082/)),建立帳號、密碼、資料庫名稱。如下:
![[20240217_212138_chrome_setup_influxdb.png]]
之後會出現一串Token如下這個要記起來。
![[20240217_212319_chrome_1894x1254_influxdb_token.png]]
## 設定 telegraf
然後打開 `./data/telegraf/telegraf.conf` ,找到 `[[outputs.influxdb_v2]]` 這個區塊,把 `urls``organization``bucket``token` 的值改為剛剛建立與複製的那一串。如圖:
![[20240217_213900_Code_setup_telegraf_ini.png]]
然後重啟 docker compose。
# 設定 InfluxDB 的 dashboard
到 [https://github.com/influxdata/community-templates#templates](https://github.com/influxdata/community-templates#templates) 挑一個 template例如 [Raspberry Pi System Template](https://github.com/influxdata/community-templates/tree/master/raspberry-pi),找到他的網址,如下:
![[20240217_213108_chrome_1864x1044_raspberrypi_template_on_github.png]]
複製這一行,然後到 InfluxDB 的 template 去把它 import 進來。如下:
![[20240217_213237_chrome_2753x1254_setup_influxdb.png]]
![[20240217_213311_chrome_2753x1254_influxdb_install_template.png]]
接著 Dashboards 就會出現一個 Raspberry Pi System 的 dashboard 了。
![[20240217_213343_chrome_1624x1120_influxdb_dashboard.png]]
點下去之後大概是長這樣:
![[20240217_214001_chrome_2604x1716_influxdb_dashboard.png]]
# 參考
- [建構 Grafana + Influxdb v2.0 + Telegraf 監控系統(docker版) - DSA Learning](https://dsalearning.github.io/grafana/influxdb-telegraf-docker/)
- [Raspberry Pi, InfluxDB, Grafana, Docker | by Anton Karazeev | Medium](https://medium.com/@antonkarazeev/raspberry-pi-influxdb-grafana-docker-a526575d6e6f#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6ImVkODA2ZjE4NDJiNTg4MDU0YjE4YjY2OWRkMWEwOWE0ZjM2N2FmYzQiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJhenAiOiIyMTYyOTYwMzU4MzQtazFrNnFlMDYwczJ0cDJhMmphbTRsamRjbXMwMHN0dGcuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJhdWQiOiIyMTYyOTYwMzU4MzQtazFrNnFlMDYwczJ0cDJhMmphbTRsamRjbXMwMHN0dGcuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMDM4MDc4MzIzNTMyNTIzMDc3NDYiLCJlbWFpbCI6ImF3aW5odWFuZ0BnbWFpbC5jb20iLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwibmJmIjoxNzA4MTQ1MjU3LCJuYW1lIjoiQXdpbiBIdWFuZyIsInBpY3R1cmUiOiJodHRwczovL2xoMy5nb29nbGV1c2VyY29udGVudC5jb20vYS9BQ2c4b2NJZjNQY0d3WjZIcDdYM204b3BjczRlNGVlZnBHQ1pGeVdMamExcjNTVVNKd1ZnPXM5Ni1jIiwiZ2l2ZW5fbmFtZSI6IkF3aW4iLCJmYW1pbHlfbmFtZSI6Ikh1YW5nIiwibG9jYWxlIjoiemgtVFciLCJpYXQiOjE3MDgxNDU1NTcsImV4cCI6MTcwODE0OTE1NywianRpIjoiNzBmNjI3NDFiNzhiYmVlMTYwNjBiZWRlOTY2YmFjYTAyZTY0ZTZkOSJ9.SXAVZ3SXny4YjIc9Cg6fNFHlXKe0jrm-4uwJ7KH41Tmo_vRAQGlbUn7MmVHXWexpKdpMCSVECC8C1VuUielC-vm8AoHMs1PLJCyhdg02hUyTqEMA08ydscfjguGP6kuI3LoMVsxkAl51C06lQi8llYZ4XGkdHxhCWP12fXQStdGPfv-64KNCkPTIfI7Teo7sfJGyjSQsDMRa4v9GWS9qmbCqut06fhpLyj0lEVfntratbuTN8ThekVfuJyJyG29U6xclm1O0NgBp-BnXML_YtBxTBV2Td_DRYY0dfcVivDKxzH135FfY5xpp_2ZIewkjJG5-pTHpin1R_XLVmIhXuA)
- [Raspberry Pi 4 使用 Grafana 监控_influxdb and grafana on raspberrypi-CSDN博客](https://blog.csdn.net/u013360850/article/details/115568985)