prometheus配置pushgateway功能測試


一、環境:

1、prometheus服務器ip:192.168.0.208

2、node-exporter客戶機ip:192.168.0.202

二、測試設計考慮:

  pushgateway類似一台信息收集中轉機,其部署位置不受任何限制。本次測試,考慮把pushgateway部署在node-exporter客戶機上,在prometheus服務器上編制信息收集和推送程序。

      信息數據流程:

  1、prometheus服務器作為信息數據采集點,通過采集和推送程序向pushgateway端推送所采集的信息數據。

  2、prometheus服務器作為prometheus服務端,從pushgateway端拉取所需信息數據用於處理和展示。

二、配置過程

1、pushgateway服務端的安裝

(1)pushgateway的image下載和安裝

[root@DL ~]# docker search pushgateway      #查詢可用pushgateway鏡像

NAME DESCRIPTION STARS OFFICIAL AUTOMATED
prom/pushgateway The Prometheus Pushgateway allows ephemeral … 45 [OK]

[root@DL ~]# docker pull prom/pushgateway

(2)pushgateway服務的運行:

[root@DL ~]# docker run -d --name=pg -p 9091:9091 prom/pushgateway

2、prometheus服務器的配置

(1)prometheus服務器對pushgateway的監控配置

[root@ELK prometheus]# vi prometheus.yml

...


- job_name: 'pushgateway'


# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.


static_configs:
- targets: ['192.168.0.202:9091']

配置完成后需要重啟一下prometheus服務:docker restart prometheus

(2)數據采集和推送程序的編制

以采集netstat命令中處於wait狀態的連接數為例:

[root@ELK prometheus]# vi node-exporter-shell.sh
#!/bin/bash
instance_name=`hostname -f | cut -d'.' -f1` #本機機器名 變量 用於之后的標簽

if [[ $instanc_name == "localhost" ]];then #要求機器名不能是localhost,不然標簽就沒有區分了
echo "Must FQDN hostname"
exit 1
fi

# For waiting connections

label="count_netstat_wait_connections" #定義一個新的key
count_netstat_wait_connections=`netstat -an | grep -i wait | wc -l` #定義一個新的數值netstat中wait的數量

echo "$label:$count_netstat_wait_connections"
echo "$label $count_netstat_wait_connections" | curl --data-binary @- http://192.168.0.202:9091/metrics/job/pushgateway/instance/$instance_name   #推送鍵值對到pushgateway服務端

(3)數據采集程序的定時運行設置

[root@ELK prometheus]# crontab -e
* * * * * sleep 10;cd /root/prometheus; ./node-exporter-shell.sh    #設置每10秒采集和推送一次數據

 三、測試

1、web訪問:http://192.168.0.202:9091/ 可看到pushgateway的實時push狀態

2、web訪問:http://192.168.0.202:9091/metrics 可看到采集數據的鍵值對

# TYPE count_netstat_wait_connections untyped
count_netstat_wait_connections{instance="ELK",job="pushgateway"} 0


數據采集和推送程序來源:B站大米運維課堂


免責聲明!

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



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