1. 程式人生 > 實用技巧 >第十講:企業級監控資料採集指令碼開發實踐

第十講:企業級監控資料採集指令碼開發實踐

  第十講內容

  • pushgateway 的介紹

  • pushgateway 的安裝和運⾏和配置

  • ⾃定義編寫指令碼的⽅法 傳送pushgateway 採集

  • 使⽤pushgateway的優缺點

  

  (⼀)pushgateway 的介紹

  pushgateway 是另⼀種採⽤被動推送的⽅式(⽽不是exporter 主動獲取)獲取監控資料的prometheus 外掛 在上篇中 我們對pushgateway已經做過介紹 它是可以單獨運⾏在 任何節點上的外掛(並不⼀定要在被監 控客戶端) 然後 通過⽤戶⾃定義開發指令碼 把需要監控的資料 傳送給 pushgateway 然後pushgateway 再把資料 推送給prometheus server

  (⼆)pushgatway的安裝和運⾏和配置

  下載地址:https://prometheus.io/download/#pushgateway

  解壓設定systemctl執行

cd /usr/local
tar -xf pushgateway-1.2.0.linux-amd64.tar.gz 
mv pushgateway-1.2.0.linux-amd64 pushgateway

  設定systemctl檔案

# cat /usr/lib/systemd/system/pushgateway.service 
[Unit]
Description=Prometheus Node Exporter
After=network.target

[Service]
ExecStart=/usr/local/pushgateway/pushgateway
User=nobody

[Install]
WantedBy=multi-user.target

  啟動

systemctl daemon-reload
systemctl start pushgateway
systemctl enable pushgateway

  關於pushgateway的配置 主要指的是 在prometheus sever端的配 置

 job_name: 'pushgateway'
    static_configs:
    - targets: ['localhost:9091','localhost:9092']

  這⾥我們發現了沒有, localhost:9091/9092 使⽤的 pushgateway開啟了兩個
  在prometheus_server 本機上 為什麼開啟兩個 最後⼀個段落給⼤家解釋


  (三)⾃定義編寫指令碼的⽅法 傳送pushgateway 採集

  接下來 進⼊重頭戲了 pushgateway 本⾝是沒有任何抓取監控資料的功能的 它只是被 動的等待推送過來