让普罗米修斯替我监测树莓派集群

背景

最近看着手里的几只树莓派在吃灰,心中不忍,遂想利用它们搭个小应用,并在新买的RPI4上监测他们的状态
以下过程参考了网上的文章,并使用了新版本的prometheus和Grafana搭配

过程

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

测试通过后可以配置supervisordsystemd等在后台运行,例如做为系统服务:

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,将下面的配置保存到 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=` 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,通过脚本可以安装最新的docker

curl -sSL https://get.docker.com | sh

4、拉取prometheus镜象

docker pull prometheus

5、用上面的配置文件以及刚才拉取的镜象,创建一个新的镜象,这个镜象直接包含了我们的配置,当然,后面可以通过配置路径挂载,将配置文件保留在宿主机主,不用每次修改都要重新打包。

FROM prom/prometheus
COPY ./prometheus.yml /etc/prometheus/prometheus.yml

6、运行容器,prometheus通过9090端口提供一个WEB UI,UI上可以看到很多指标,但略丑。

docker run -p 9090:9090 --name prometheus-rpi -d prometheus/rpi-monitor

7、运行grafana

由于我这里安装的是32位的ARM,所以需要拉取32位的镜象,需要64位arm的朋友可以到hub.docker.com自行寻找相应的镜象

docker run -i -p 3000:3000 --name grafana6 grafana/grafana-arm32v7-linux:6.5.1

8、接下来就是配置datasource为prometheus,导入dashboard模板,模板ID为 8919,最终效果如下图

效果

参考文章

树莓派教程:使用监控系统 Prometheus 监控 Raspberry Pi 集群

【监控】Prometheus+Grafana监控简介

https://github.com/prometheus/node_exporter

你可能感兴趣的:(让普罗米修斯替我监测树莓派集群)