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