wordpress不能mp4百度首頁排名優(yōu)化平臺
Prometheus之PushGateway
文章目錄
- Prometheus之PushGateway
- 介紹作用
- 資源列表
- 基礎(chǔ)環(huán)境
- 一、部署PushGateway
- 1.1、下載軟件包
- 1.2、解壓軟件包
- 1.3、編輯配置systemctl啟動文件
- 1.4、創(chuàng)建日志目錄
- 1.5、加載并啟動
- 1.6、監(jiān)控端口
- 1.7、訪問PushGateway
- 二、 配置Prometheus抓取PushGateway數(shù)據(jù)
- 三、被監(jiān)控服務(wù)推送數(shù)據(jù)到PushGateway
- 四、查看是否推送數(shù)據(jù)
介紹作用
- PushGateway為Promethus整體監(jiān)控方案的功能組件之一,并作為一個(gè)獨(dú)立的工具存在。它主要用于Prometheus無法直接拿到監(jiān)控指標(biāo)的場景,如監(jiān)控源位于防火墻之后,Prometheus無法穿透防火墻,目標(biāo)服務(wù)器沒有可抓取監(jiān)控?cái)?shù)據(jù)的端點(diǎn)等多種情況。在類似的場景中,可通過部署PushGateway的方式解決問題。
- 當(dāng)部署該組件后,監(jiān)控源通過主動發(fā)送監(jiān)控?cái)?shù)據(jù)到PushGateway,再又Prometheus定時(shí)獲取信息,實(shí)現(xiàn)資源的狀態(tài)監(jiān)控。
資源列表
操作系統(tǒng) | 配置 | 主機(jī)名 | IP |
---|---|---|---|
CentOS 7.9 | 2C4G | prometheus-server | 192.168.93.101 |
CentOS 7.9 | 2C4G | node-exporter | 192.168.93.102 |
CentOS 7.9 | 2C4G | grafana | 192.168.93.103 |
CentOS 7.9 | 2C4G | push-gateway | 192.168.93.104 |
基礎(chǔ)環(huán)境
- 關(guān)閉防火墻
systemctl stop firewalld
systemctl disable firewalld
- 關(guān)閉內(nèi)核安全機(jī)制
setenforce 0
sed -i "s/^SELINUX=.*/SELINUX=disabled/g" /etc/selinux/config
- 修改主機(jī)名
hostnamectl set-hostname prometheus-server
hostnamectl set-hostname node-exporter
hostnamectl set-hostname grafana
hostnamectl set-hostname push-gateway
一、部署PushGateway
- PushGatway可以隨便找一臺機(jī)器單獨(dú)部署或者和Prometheus或node-exporter部署在一起,用來接收數(shù)據(jù)
1.1、下載軟件包
wget https://github.com/prometheus/pushgateway/releases/download/v1.6.1/pushgateway-1.6.1.linux-amd64.tar.gz
1.2、解壓軟件包
[root@push-gateway ~]# tar -zxvf pushgateway-1.6.1.linux-amd64.tar.gz -C /usr/local/bin/ pushgateway-1.6.1.linux-amd64/pushgateway --strip-components=1
1.3、編輯配置systemctl啟動文件
[root@push-gateway ~]# cat > /etc/systemd/system/pushgatway.service <<EOF
[Unit]
Description=Pushgateway
After=network.target[Service]
ExecStart=/usr/local/bin/pushgateway \--web.listen-address=:9091 \--persistence.file=/prometheus/data/pushgatway.log \--persistence.interval=5m \--log.level=info \--log.format=json[Install]
WantedBy=multi-user.target
EOF
1.4、創(chuàng)建日志目錄
[root@push-gateway ~]# mkdir -p /prometheus/data/
1.5、加載并啟動
[root@push-gateway ~]# systemctl daemon-reload
[root@push-gateway ~]# systemctl enable pushgatway.service --now
1.6、監(jiān)控端口
- PushGateway默認(rèn)監(jiān)聽
9090
端口
[root@push-gateway ~]# netstat -anpt | grep 9091
tcp6 0 0 :::9091 :::* LISTEN 8307/pushgateway
1.7、訪問PushGateway
- 訪問地址:http://192.168.93.104:9091
二、 配置Prometheus抓取PushGateway數(shù)據(jù)
[root@prometheus-server ~]# vim /usr/local/prometheus/prometheus.yml
# 添加如下內(nèi)容- job_name: "prometheus-pushgateway" # 監(jiān)控的名字honor_labels: true # 解決pushgateway組件的標(biāo)簽和prometheus服務(wù)標(biāo)簽沖突,false(默認(rèn)),將標(biāo)簽加上前綴"exporter_",不覆蓋。true,覆蓋原來的標(biāo)簽static_configs: # 靜態(tài)配置發(fā)現(xiàn)目標(biāo)- targets: ["192.168.93.104:9091"] # 監(jiān)控的地址
# 刷新Prometheus服務(wù)
[root@prometheus-server ~]# curl -X POST http://192.168.93.101:9090/-/reload
- 瀏覽器查看,Prometheus抓取PushGatway數(shù)據(jù)聯(lián)通了,但是還沒有數(shù)據(jù)
三、被監(jiān)控服務(wù)推送數(shù)據(jù)到PushGateway
[root@node-exporter ~]# echo "user_num 22" | curl --data-binary @- http://192.168.93.104:9091/metrics/job/xinjizhiwa_user/instance/192.168.93.102# 參數(shù)說明
echo "key value" | curl --data-binary @- http://pushgatway的ip:端口號/metrics/job/自定義job名稱/instance/被監(jiān)控節(jié)點(diǎn)的ip地址
四、查看是否推送數(shù)據(jù)
-
查看PushGateway是否有數(shù)據(jù)
-
查看PushGateway是否把數(shù)據(jù)推送到Prometheus