安装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
分类:
Prometheus
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统