小工具知识网

当前位置: 首页 > 行业知识 > 【prometheus】Pushgateway安装和使用

行业知识

【prometheus】Pushgateway安装和使用

2026-11-01 06:15:31 来源:互联网转载

目录

一、Pushgateway概述

1.1 Pushgateway简介

1.2 Pushgateway优点

1.3 pushgateway缺点

二、测试环境

三、安装测试

3.1 pushgateway安装

3.2 prometheus添加pushgateway

3.3 推送指定的数据格式到pushgateway

1.添加单条数据

2.添加复杂数据

3.SDk-prometheus-client使用



【Prometheus】概念和工作原理介绍_prometheus工作原理-CSDN博客

【Prometheus】k8s集群部署node-exporter_kubectl 安装 promethues node-exporter-CSDN博客

【prometheus】k8s集群部署prometheus server-CSDN博客

【prometheus】k8s集群部署Grafana安装和配置|Prometheus监控K8S

【prometheus】k8s集群部署AlertManager实现邮件和钉钉告警-CSDN博客

【prometheus】监控MySQL并实现可视化-CSDN博客

【prometheus】监控nginx-CSDN博客


一、Pushgateway概述


1.1 Pushgateway简介


Pushgateway是prometheus的一个组件,prometheus server默认是通过exporter主动获取数据(默认采取pull拉取数据),pushgateway则是通过被动方式推送数据到prometheus server,用户可以写一些自定义的监控脚本把需要监控的数据发送给pushgateway, 然后pushgateway再把数据发送给Prometheus server。

1.2 Pushgateway优点


  • Prometheus 默认采用定时pull 模式拉取targets数据,但是如果不在一个子网或者防火墙,prometheus就拉取不到targets数据,所以可以采用各个target往pushgateway上push数据,然后prometheus去pushgateway上定时pull数据
  • 在监控业务数据的时候,需要将不同数据汇总, 汇总之后的数据可以由pushgateway统一收集,然后由 Prometheus 统一拉取。

    1.3 pushgateway缺点


    • Prometheus拉取状态只针对 pushgateway, 不能对每个节点都有效;
    • Pushgateway出现问题,整个采集到的数据都会出现问题
    • 监控下线,prometheus还会拉取到旧的监控数据,需要手动清理 pushgateway不要的数据。

      二、测试环境


      IP

      主机名

      192.168.2.139

      master1

      192.168.40.140

      node1


      三、安装测试


      3.1 pushgateway安装


      在node1节点操作

      docker pull prom/pushgatewaydocker run -d --name pushgateway -p 9091:9091 prom/pushgateway

      在浏览器访问192.168.2.140:9091出现如下ui界面

      3.2 prometheus添加pushgateway


      修改prometheus-cfg.yaml文件

      - job_name: 'pushgateway'      scrape_interval: 5s      static_configs:      - targets: ['192.168.2.140:9091']   honor_labels: true

      更新

      kubectl apply -f prometheus-alertmanager-cfg.yamlkubectl delete -f prometheus-alertmanager-deploy.yamlkubectl apply  -f prometheus-alertmanager-deploy.yaml

      登录prometheus http://192.168.2.139:30242/targets

      3.3 推送指定的数据格式到pushgateway


      1.添加单条数据

      # 向 {job="test_job"} 添加单条数据:echo " metric 3.6" | curl --data-binary @- http://192.168.2.140:9091/metrics/job/test_job

      这里需要注意的是将推送给pushgateway,curl --data-binary是将HTTP POST请求中的数据发送给HTTP服务器(pushgateway),和用户提交THML表单时浏览器的行为是一样的,HTTP POST请求中的数据为纯二进制数据。

      prometheus web中查询

      2.添加复杂数据

      # 添加复杂数据cat 

上一篇:华为李鹏:激发新增长,引领5G-A商用元年

下一篇:轻松查找使用过的QQ小程序秘籍!