安装pushgateway
下载并启动,9091端口有web界面
wget https://github.com/prometheus/pushgateway/releases/download/v1.4.3/pushgateway-1.4.3.linux-amd64.tar.gz -C /apps
tar -xvf pushgateway-1.4.3.linux-amd64.tar.gz
ln -sv pushgateway-1.4.3.linux-amd64 pushgateway
cd /apps/pushgateway
./pushgateway
prometheus添加配置
vim prometheus.yml
- job_name: 'pushgateway-monitor'
scrape_interval: 15s
static_configs:
- targets: ['10.211.55.22:9091']
honor_labels: true
推送一个job名称为mytest_job key为mytest_metric,value为2022
echo "mytest_metric 2022" | curl --data-binary @- http://10.211.55.22:9091/metrics/job/mytest_job
在pushgateway查看有没有值
在查看prometheus数据有没有过来,我这里可以正常看到。
写一个脚本往pushgateway传输数据,执行脚本
[root@k8s-node2 ~]# cat mem_monitor.sh
#!/bin/bash
total_memory=$(free |awk '/Mem/{print $2}')
used_memory=$(free |awk '/Mem/{print $3}')
job_name="custom_memory_monitor"
instance_name=`ifconfig eth0 | grep -w inet | awk '{print $2}'`
pushgateway_server="http://10.211.55.22:9091/metrics/job"
cat <<EOF | curl --data-binary @- ${pushgateway_server}/${job_name}/instance/${instance_name}
#TYPE custom_memory_total gauge
custom_memory_total $total_memory
#TYPE custom_memory_used gauge
custom_memory_used $used_memory
EOF
查看pushgeway是否有数据
prometheus也可以看到数据
删除pushgateway数据,也可以直接web界面删除
curl -X DELETE http://10.211.55.22:9091/metrics/job/custom_memory_monitor/instance/10.211.55.22