背景
最近看着手里的几只树莓派在吃灰,心中不忍,遂想利用它们搭个小应用,并在新买的RPI4上监测他们的状态
过程
1、在各监测点上安装node_exporter
cd /home
curl -SL https://github.com/prometheus/node_exporter/releases/download/v0.16.0/node_exporter-0.16.0.linux-armv7.tar.gz > node_exporter.tar.gz && sudo tar -xvf node_exporter.tar.gz -C /usr/local/bin/ --strip-components=1
2、运行node_exporter
node_exporter
后面可以做为系统服务
vim /etc/systemd/system/node_exporter.service
输入
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=root
ExecStart=/home/node_exporter
[Install]
WantedBy=default.target
开机启动
systemctl daemon-reload
systemctl status node_exporter
systemctl start node_exporter
systemctl enable node_exporter
3、在监测机上配置prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
- job_name: 'RPi_Mariadb'
static_configs:
- targets: ['192.168.10.10:9100']
- job_name: 'RPi_Redis'
static_configs:
- targets: ['192.168.10.11:9100']
- job_name: 'RPi_dotnet'
static_configs:
- targets: ['192.168.10.12:9100']
3、安装docker
curl -sSL https://get.docker.com | sh
4、拉取镜象
docker pull prometheus
5、用上面的配置文件,创建一个新的镜象
FROM prom/prometheus
COPY ./prometheus.yml /etc/prometheus/prometheus.yml
6、运行容器
docker run -p 9090:9090 --name prometheus-rpi -d prometheus/rpi-monitor
7、运行grafana
docker run -i -p 3000:3000 --name grafana6 grafana/grafana-arm32v7-linux:6.5.1
8、配置datasource,导入dashboard 8919,最终效果如下图