当前位置: 首页 > news >正文

Prometheus之Pushgateway使用

Pushgateway属于整个架构图的这一部分

The Pushgateway is an intermediary service which allows you to push metrics from jobs which cannot be scraped. The Prometheus Pushgateway exists to allow ephemeral and batch jobs to expose their metrics to Prometheus. Since these kinds of jobs may not exist long enough to be scraped, they can instead push their metrics to a Pushgateway. The Pushgateway then exposes these metrics to Prometheus.

官方解释,Pushgateway是一个“中间人”服务,你可以把短期job的metrics push到Pushgateway,然后Prometheus从Pushgateway那里pull。

想象一下,如果没有Pushgateway,你为了监控short-lived jobs,就得把它们放到Prometheus的targets中,这样target越来越多,而且因为它是短期作业,这个target将长时间处于down的状态,这样确实不太优雅。

短期作业最好是 service-level(不包含特定的机器或实例标签)而不是 machine-level,以便将特定机器或实例的生命周期与推送的指标脱钩。

Pushgateway的另一个应用场景是,在网络不通的环境下充当一个中间人。比如因为网络原因,Prometheus不能直接从被监控对象pull数据,但是可以从Pushgateway那里pull,并且Pushgateway和被监控对象之间网络也是通的。这个场景虽然理论上可行,但是,官方更推荐使用PushProx( which allows Prometheus to traverse a firewall or NAT)

安装使用

到github https://github.com/prometheus/pushgateway 的release下载二进制包,解压后直接运行,默认端口是 9091

修改Prometheus配置文件,将Pushgateway添加为target,然后启动Prometheus

scrape_configs:- job_name: "pushgateway"static_configs:- targets: ["ip:9091"]

可通过向Pushgateway发put 或 post 请求进行数据推送。例:

echo "some_metric 3.14" | curl --data-binary @- http://pushgateway_ip:9091/metrics/job/some_job

去Prometheus就能查到刚刚推送的数据:

需要说明的是,因为Pushgateway是作为一个target写在Prometheus配置文件中的,所以Prometheus自动加了job="pushgateway"**instance**="192.168.243.99:9091"的标签,而自己加的job=some_job标签,因为和默认标签重名,被重命名成了exported_job。要想自定义的标签覆盖默认标签的修改Prometheus配置文件,增加honor_labels: true :

scrape_configs:- job_name: "pushgateway"honor_labels: truestatic_configs:- targets: ["ip:9091"]

将数据清空,再次向Pushgateway推送数据,查看发现自定义标签已经覆盖了默认标签:

使用Pushgateway需要注意的是:向Pushgateway推送的数据,Pushgateway会一直保存着,下次Prometheus来pull数据时,Pushgateway又会把之前保存的数据交给Prometheus(见上图,查5分钟内的数据,尽管我只向Pushgateway推了一次数据),除非手动调用删除接口:curl -X DELETE http://127.0.0.1:9091/metrics/job/some_job

原文:The Pushgateway never forgets series pushed to it and will expose them to Prometheus forever unless those series are manually deleted via the Pushgateway’s API

Prometheus还支持多种语言的客户端(如java/go/python 等)向Pushgateway推送数据,可参考官方文档各语言的示例

更多详细文档,参考github Pushgateway

http://www.lryc.cn/news/452931.html

相关文章:

  • Rust Web开发常用库
  • ios内购支付-支付宝APP支付提现
  • 新课发布|鸿蒙HarmonyOS Next商城APP应用开发实战
  • 基于Java,SpringBoot,Vue智慧校园健康驿站体检论坛请假管理系统
  • 【数据分享】2001-2023年我国省市县镇四级的逐月平均气温数据(免费获取/Shp/Excel格式)
  • c#代码介绍23种设计模式_16迭代器模式
  • 408算法题leetcode--第23天
  • 帝国CMS系统开启https后,无法登陆后台的原因和解决方法
  • 根据视频id查询播放量
  • 初始爬虫11
  • SSY20241002提高组T4题解__纯数论
  • Python:lambda 函数详解 以及使用
  • 【C++】空指针和野指针
  • 大模型提示词
  • 在线css像素px到Em的转换器
  • 回溯算法解决排列组合及子集问题
  • Unity中Mesh多种网格绘制模式使用方法参考
  • 【Spring Security】基于SpringBoot3.3.4版本②如何配置免鉴权Path
  • 信息学奥赛复赛复习11-CSP-J2020-04方格取数-动态规划、斐波那契数列、最优子结构、重叠子问题、无后效性
  • Hive数仓操作(十二)
  • 计算机毕业设计 基于SpringBoot和Vue的课程教学平台的设计与实现 Java实战项目 附源码+文档+视频讲解
  • 有状态(Session) VS 无状态(Token)
  • 天坑!Spark+Hive+Paimon+Dolphinscheduler
  • JAVA——IO框架
  • 项目管理系统如何实现项目申报流程自动化?
  • ndb9300public-ndb2excel简介
  • C++:const成员
  • 基于ROS的激光雷达点云物体检测
  • 大模型训练环境搭建
  • 使用Java调用GeoTools实现全球国家矢量数据入库实战