pushgateway 简介
pushgateway用于临时的指标数据收集。
- pushgateway不支持数据领取(pull模式),需要客户端 主动将数据推送给pushgateway。
- pushgateway可以单独运行在一个节点,然后需要自定 义监控脚本把需要监控的主动推送给pushgateway的 API接口,然后pushgateway再等待prometheus server 抓取数据,即pushgateway本身没有任何抓取监控数据 的功能,目前pushgateway只能被动的等待数据从客户 端进行推送。
- --persistence.file="" #数据保存的文件,默认只保存在 内存中
- --persistence.interval=5m #数据持久化的间隔时间
安装
https://prometheus.io/download/#pushgateway
# step1
mkdir -p /apps;cd /apps
wget https://github.com/prometheus/pushgateway/releases/download/v1.5.1/pushgateway-1.5.1.linux-amd64.tar.gz
tar -xf pushgateway-1.5.1.linux-amd64.tar.gz
ln -sv /apps/pushgateway-1.5.1.linux-amd64 /apps/pushgateway
# step2
[root@iZ0jlhtwpysrlkmr5iq8ioZ apps]# cat /etc/systemd/system/pushgateway.service
[Unit]
Description=Prometheus pushgateway
After=network.target
[Service]
ExecStart=/apps/pushgateway/pushgateway
[Install]
WantedBy=multi-user.target
#step3
systemctl daemon-reload && systemctl start pushgateway && systemctl enable pushgateway
启动成功标志
数据流
发送数据 PushGateway
客户端推送单条指标数据: 要 Push 数据到 PushGateway 中,可以通过其提供的 API 标准接口来添加,默认 URL 地址为: http://:9091/metrics/job/{//} 其中是必填项,是job的名称,后边可以跟任意数量的标签对,一般我们会添加一个 instance/实例名称标签,来方便区分各个指标是在哪个节点产生的。 如下推送一个job名称为mytest_job,key为mytest_metric值为2022
[root@hybrid01 apps]# echo "mytest_metric 2088" | curl --data-binary @- http://172.30.66.174:9091/metrics/job/mytest_job
prometheus配置数据采集
prometheus配置数据采集:
root@prometheus-server1:/apps/prometheus# vim /apps/prometheus/prometheus.yml - job_name: 'pushgateway-monitor'
scrape_interval: 5s
static_configs: - targets: ['172.31.1.102:9091']