node_exporter+prometheus+grafana监控系统搭建


一、目标

  收集并监控服务器cpu、内存、磁盘数据,超出阈值告警,告警通知到钉钉群。

二、部署图

 

    将prometheus、node_exporter、grafana、启动脚本qidong文件夹、prometheus配置好的文件夹上传到192.168.1.100服务器上,我们将这些二进制包和rpm包放到 /usr/local/src 目录下;

将node_exporter、启动脚本qidong文件夹上传到192.168.1.101服务器 /usr/local/src 目录下。

三、部署

3.1.部署node_exporter

 1.解压:

cd /usr/local/src/
tar -zxvf node_exporter-0.18.1.linux-amd64.tar.gz -C /usr/local/

 2.重命名:

cd /usr/local/
mv node_exporter-0.18.1.linux-amd64/ node_exporter

3.复制写好的启动脚本:

cd /usr/local/src/qidong
cp node_exporter.service /usr/lib/systemd/system/node_exporter.service

开机启动脚本node_exporter.service如下:

Description=node_exporter

Documentation=https://prometheus.io/

After=network.target

[Service]

Type=simple

#User=prometheus

ExecStart=/usr/local/node_exporter/node_exporter  --web.listen-address=:7203

Restart=on-failure

[Install]

WantedBy=multi-user.target
 

4.使用

开机启动:systemctl enable node_exporter
开:systemctl start node_exporter
查:systemctl status node_exporter

监听端口:7203

data metrics:
http://ip:端口/metrics
 

3.2.部署prometheus

  1.解压:
cd /usr/local/src
tar -zxvf prometheus-2.12.0.linux-amd64.tar.gz -C /usr/local/
2.重命名:
cd /usr/local
mv prometheus-2.12.0.linux-amd64/ prometheus

 3.复制写好的配置文件到相应目录:

cd /usr/local/src/prometheus
cp prometheus.yml /usr/local/prometheus/prometheus.yml
cp -r targets/ /usr/local/prometheus/targets

prometheus.yml:

global:
  scrape_interval: 120s
  scrape_timeout: 60s
  evaluation_interval: 120s
scrape_configs:
- job_name: 'prometheus'
  static_configs:
  - targets: ['localhost:8090']
- job_name: 'common'
  file_sd_configs:
  - files:
    - 'targets/tg_*.json'

4.复制开机启动脚本prometheus.service:

cd /usr/local/src/qidong
cp prometheus.service /usr/lib/systemd/system/prometheus.service

prometheus.service脚本内容:

#脚本内容
[Unit]

Description=Prometheus

Documentation=https://prometheus.io/

After=network.target

 

[Service]

# Type设置为notify时,服务会不断重启

Type=simple

#User=prometheus

# --storage.tsdb.path是可选项,默认数据目录在运行目录的./dada目录中

ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/home/software/prometheus-data --web.enable-lifecycle --web.listen-address=:8090

Restart=on-failure

 

[Install]

WantedBy=multi-user.target
 

5.使用:

自启动:systemctl enable prometheus
开:systemctl start prometheus
查:systemctl status prometheus
重启:systemctl restart prometheus

3.3.部署grafana

  1.安装
cd /usr/local/src/
yum -y localinstall grafana-6.7.2-1.x86_64.rpm
安装插件:grafana-cli plugins install grafana-piechart-panel 1.3.8
 

2.使用命令

开机自启:systemctl enable grafana-server.service
开: systemctl start grafana-server
查: systemctl status grafana-server

启动后访问:
默认:
http://ip:3000
账号:admin
默认:admin

3.配置promethues数据源

 

 

 

 

  4.配置node_exporter的dashboard
 

https://grafana.com/grafana/dashboards/11074

想应exporter有相应的模板编号,可以通过官网查询

使用该模板:

 

 

  5.配置告警
1.grafana钉钉配置:

 

 

 url:为钉钉发送接口

  2.告警群钉钉机器人设置:
 
 群设置=》智能群助手=》添加机器人=》自定义

 

 新增时会有url,保存下来,为上文grafana设置告警通知使用。

  3.panel设置告警(以cpu使用率为例)
 
 
 

 

4.修改grafana配置

 vi  /etc/grafana/grafana.ini
 

5.重启:

systemctl restart grafana-server

 告警钉钉收到消息 效果展示:

 

 

安装包及文件配置 网盘路径:

链接:https://pan.baidu.com/s/1qt7SSECAOLZmflWPcapjwg
提取码:j6aw


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM