Prometheus监控服务器状态及预警

发布时间 2023-11-16 18:37:17作者: 钱塘江畔

1. 背景

项目上线后,需要对服务器及进程进行持续监控及预警。

2.方案

使用Prometheus收集监控指标,使用Node_exporter收集服务器状态,使用Grafana进行可视化展示及发送预警。

2.1 Node_exporter安装及使用

nohup ./node_exporter --web.listen-address 0.0.0.0:8071 &

2.2 Prometheus收集Node_exporter数据

# 修改配置文件
vi prometheus.yml
# 启动
nohup ./prometheus --config.file=prometheus.yml --web.listen-address=0.0.0.0:8072 &

2.3 部署Grafana及可视化

# 修改配置文件,默认端口改为8083 ;也有说修改 custom.ini 
vi defaults.ini

# 启动 
nohup ./bin/grafana-server web & 

# 登录  admin/admin

  (
      1
    -
        sum by (job, mountpoint) (node_filesystem_free_bytes{mountpoint=~"/data01.*?"})
      /
        sum by (job, mountpoint) (node_filesystem_size_bytes{mountpoint=~"/data01.*?"})
  )
*
  100

2.4 Grafana发送预警


3. 引用

如何用 Prometheus 和 Grafana 实现集群的监控预警