Prometheus分布式監控


一、概述

prometheus安裝在阿里雲上面,監控節點在公司內部機房,2個網絡直接是不互通的。

環境說明

阿里雲服務器:

操作系統:centos 7.6

數量:1台

 

公司內部服務器

操作系統:centos 7.6

數量:1台

 

拓撲圖

 

 說明:

1. 公司內部服務器安裝node-exporter插件,收集主機信息,通過調用curl命令,將收集的數據以POST方式發送給Pushgateway

2. Pushgateway負責接收數據

3. Prometheus從Pushgateway中拉取數據,結合Grafana做數據展示。

 

二、部署操作

阿里雲服務器

Prometheus和Pushgateway,是直接docker部署的。具體安裝操作,請參考鏈接:

https://www.cnblogs.com/xiao987334176/p/9930517.html

https://www.cnblogs.com/xiao987334176/p/9933963.html

 

這里重點要說明的是Prometheus配置Pushgateway時,必須要加一個參數honor_labels: true

  - job_name: 'pushgateway'
    honor_labels: true
    static_configs:
      - targets: ['172.18.156.172:9091']
        labels:
          instance: xxx

如果不加,會造成推送給Pushgateway的instance和job全部加了"exported_"前綴。

那么在Grafana現有的模板中,無法展示推送到Pushgateway的數據。

 

公司內部服務器

安裝node-exporter

這里推薦使用二進制方式

wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
tar zxvf node_exporter-0.18.1.linux-amd64.tar.gz -C /data/
mv /data/node_exporter-0.18.1.linux-amd64 /data/node_exporter

 

封裝service

vi /etc/systemd/system/node-exporter.service

內容如下:

[Unit]
Description=Prometheus Node Exporter
After=network.target
[Service]
ExecStart=/data/node_exporter/node_exporter
[Install]
WantedBy=multi-user.target

注意:主要修改ExecStart和User

 

設置開機自啟動

systemctl daemon-reload
systemctl enable node-exporter
systemctl start node-exporter

 

查看端口

# ss -tunlp|grep node
tcp    LISTEN     0      128      :::9100                 :::*                   users:(("node_exporter",pid=990,fd=3))

 

備注

node-exporter也可以使用docker方式安裝,但是收集磁盤數據時,它采集的數據和真實物理主機是不一樣的。

比如執行:df -hT

 

可能會比真實的多幾個目錄。

因此,我還是推薦使用二進制方式安裝,這樣數據會比較准確一點。

 

發送POST請求

將node_exporter收集到的數據傳送監控數據到pushgateway

對於傳過去的監控項會添加此處定義的標簽 job=node_exporter instance=北京三里屯  hostname=192.168.2.45

curl 127.0.0.1:9100/metrics|curl --data-binary @- http://114.114.114.114:9091/metrics/job/node_exporter/instance/北京三里屯/hostname/192.168.2.45

 

訪問pushgateway頁面

http://114.114.114.114:9091

效果如下:

 

 

 訪問Grafana,查看主機信息

 

 

 

本文參考鏈接:

https://www.cnblogs.com/huandada/p/10932953.html

https://www.jianshu.com/p/51b9338d98b0


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM