Pushgateway 采集数据
· 阅读需 4 分钟
Pushgateway 基本概念
Pushgateway 是采用被动推送的方式,而不是类似于prometheus server 主动连接 exporter获取监控数据
pushgateway 可以单独运行在一个节点,然后需要自定义监控脚本把需要监控的主动推送给pushgateway的API接口,然后 pushgateway 等待 prometheus server 抓取数据,即 pushgateway 本身没有任何抓取监控数据的功能,目前 pushgateway 只是被动的等待数据从客户端推送过来
--persistence.file="" #数据保存的文件,默认只保存在内存中
--persistence.interval=5m #数据持久化的间隔时间
部署 pushgateway
# docker 部署
docker run -d --name pushgateway -p 9091:9091 prom/pushgateway
# 二进制安装
cd /apps
wget https://github.com/prometheus/pushgateway/releases/download/v1.4.2/pushgateway-1.4.2.linux-amd64.tar.gz
tar zxf pushgateway-1.4.2.linux-amd64.tar.gz
# 编写 centos7 控制脚本
cat > /etc/systemd/system/pushgateway.service << EOF
[Unit]
Description=pushgateway
After=network.target
[Service]
Restart=on-failure
WorkingDirectory=/apps/pushgateway
ExecStart=/apps/pushgateway/pushgateway # 如果需要持久化pushgateway数据,可以加上--persistence.file="" 和--persistence.interval=5m 两个参数
[Install]
WantedBy=multi-user.target
EOF
prometheus 到 pushgateway 采集数据
验证 pushgateway
curl 192.168.15.100:9091/metrics
prometheus 配置数据采集
vim prometheus-cfg.yaml
- job_name: 'pushgateway-monitor'
scrape_interval: 5s
static_configs:
- targets: ['192.168.15.100:9091']
honor_labels: true
- honor_labels 控制 Prometheus 如何处理已经存在于已抓取数据中的标签与 Prometheus 将附加服 务器端的标签之间的冲突("job"和"instance"标签,手动配置的目标标签以及服务发现实现生成的标签)
- 如果 honor_labels 设置为 "true",则通过保留已抓取数据的标签值并忽略冲突的服务器端标签来解决标签冲突
- 如果 honor_labels 设置为 "false",则通过将已抓取数据中的冲突标签重命名为 "exported_
<original-label>" (例如 "exported_instance", "exported_job") 然后附加服务器端标签来解决标签冲突
kubectl apply -f prometheus-cfg.yaml
kubectl delete -f prometheus-deploy.yaml
kubectl applt -f prometheus-deploy.yaml
## 验证一下数据
查看 prometheus 在 target 中是否存在 pushgateway