虚拟空间网站回收池有什么作用,网页视频下载网址,seo推广优化方案,全国城市雕塑建设官方网站文章目录 一、前言二、PushGateway安装三、PushGateway的使用四、PushGateway脚本思路 一、前言
pushgateway相比较exporter是主动向服务器发送请求#xff0c;pushgateway本身也是一个程序#xff0c;可以运行在任意节点上(不是必须在被监控端)#xff0c;运行本身没有抓取… 文章目录 一、前言二、PushGateway安装三、PushGateway的使用四、PushGateway脚本思路 一、前言
pushgateway相比较exporter是主动向服务器发送请求pushgateway本身也是一个程序可以运行在任意节点上(不是必须在被监控端)运行本身没有抓取数据的功能它只是被动的等待推送过来然后发现服务端。
二、PushGateway安装
1、GitHub下载解压 PushGateway下载地址 wget https://github.com/prometheus/pushgateway/releases/download/v1.5.0/pushgateway-1.5.0.linux-amd64.tar.gz2、运行pushgateway 默认端口是9091可以使用--web.listen-address更改默认端口
tar zxf pushgateway-1.5.0.linux-amd64.tar.gz
mv pushgateway-1.5.0.linux-amd64 /usr/local/pushgateway
cd /usr/local/pushgateway
./pushgateway --web.listen-address:19091PS前台启动没有报错就可以 ^C 停止掉了我们配置systemd管理
3、配置system管理
cat /usr/lib/systemd/system/pushgateway.service EOF
[Unit]
Descriptionprometheus pushgateway
Afternetwork.target[Service]
Typesimple
Userroot
Grouproot
ExecStart/usr/local/pushgateway/pushgateway --web.listen-address:19091
ExecStop/usr/bin/kill -HUP \$MAINPID[Install]
WantedBymulti-user.target
EOF启动并加入开机自启动
systemctl enable pushgateway.service --now
systemctl status pushgateway.service如上图查看状态是active (running)表示已经起来了
4、Prometheus配置文件中添加PushGateway地址 - job_name: prometheus gatewaystatic_configs:- targets: [localhost:19091]systemctl restart prometheus.service
systemctl status prometheus.service5、验证 浏览器访问 IP:19091 验证pushgateway页面 验证Prometheus页面
三、PushGateway的使用
1、推送单个样本
echo test_metric 1314521 | curl --data-binary - http://localhost:19091/metrics/job/test_jobpushgateway页面可以看到推送的数据 如下图所示
test_metric 1314521: 推送的键 值job/test_job标签jobtest_job多个标签直接往后添加即可data-binary发送post请求 以二进制数据
四、PushGateway脚本思路
使用shell脚本推送 netstat wait数量
#!/bin/bash
pushgatewaylocalhost:19091
lablecount_netstat_wait_connections
count_netstat_wait_connections$(netstat -an|grep -i wait|wc -l)if [ ${HOSTNAME} localhost ];thenecho 主机名不可使用 localhost exit 5
fi# 这里定义了两个标签 jobpushgateway-1 hostname${HOSTNAME}
echo ${lable} $count_netstat_wait_connections|curl --data-binary - http://${pushgateway}/metrics/job/pushgateway-1/hostname/${HOSTNAME}执行脚本 检查是否能推送到pushgateway页面
使用定时任务执执行脚本每3秒推送一次数据
crontab -e
* * * * * /usr/bin/sleep 3; /bin/bash /root/qinzt/pushgateway.shprometheus中查询数据