Centos7的prometheus+grafana添加主机监控

注:    Grfana官方仪表盘下载:https://grafana.com/dashboards
          数据源推荐:https://grafana.com/dashboards/9276

一、首先在Linux系统上安装一个探测器node explorer, 下载地址https://prometheus.io/docs/guides/node-exporter/
这个探测器会定期将linux系统的各项硬件指标和内核参数通过9100端口和url metrics暴露给外部。

1、下载https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz

查看自己服务器的内核是amd还是arm,进行选择下载对应的安装包。
lsb_release -a

Centos7的prometheus+grafana添加主机监控
2、解压
tar -xvf node_exporter-1.0.1.linux-amd64.tar.gz -C /usr/local
mv /usr/local/node_exporter-1.0.1.linux-amd64 /usr/local/node_exporter

3、启动
cd /usr/local
nohup /usr/local/node_exporter/node_exporter &

4、查看进程是否启动正常
ps -ef | grep node_exporter
或者查看端口
netstat -ntlp | grep 9100

5、验证是否采集数据
curl IP:9100/metrics。如下展示部分数据

查看cpu数据
curl IP:9100/metrics | grep cpu

Centos7的prometheus+grafana添加主机监控

6、在prometheus的配置文件上添加配置
vi prometheus.yml
  - job_name: 'nginx01'
    static_configs:
      - targets: ['192.168.5.200:9100']

7、重启prometheus服务
]# ps -ef | grep prometheus
]# kill -9 id
/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml &

8、打开prometheus的web界面http://IP:9090,查看有监控到

Centos7的prometheus+grafana添加主机监控

9、到grafana上导入可视化模板,点击Import

Centos7的prometheus+grafana添加主机监控

10、如下输入模板数字,随便点击一下其他地方,自动跳转页面

Centos7的prometheus+grafana添加主机监控

Centos7的prometheus+grafana添加主机监控

如下导入后,可以看到监控到的各种数据可视化。

Centos7的prometheus+grafana添加主机监控

 

后续更新部署prometheus+grafana。