【prometheus】Pushgateway安装和使用

2024-06-04 7829阅读

【prometheus】Pushgateway安装和使用 第1张

目录

一、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。【prometheus】Pushgateway安装和使用 第2张

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/pushgateway
      docker run -d --name pushgateway -p 9091:9091 prom/pushgateway

      在浏览器访问192.168.2.140:9091出现如下ui界面【prometheus】Pushgateway安装和使用 第3张

      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.yaml
      kubectl delete -f prometheus-alertmanager-deploy.yaml
      kubectl apply  -f prometheus-alertmanager-deploy.yaml

      登录prometheus http://192.168.2.139:30242/targets【prometheus】Pushgateway安装和使用 第4张

      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】Pushgateway安装和使用 第5张

      prometheus web中查询

      【prometheus】Pushgateway安装和使用 第6张

      2.添加复杂数据

      # 添加复杂数据
      cat 

    免责声明:我们致力于保护作者版权,注重分享,被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理! 图片声明:本站部分配图来自人工智能系统AI生成,觅知网授权图片,PxHere摄影无版权图库和百度,360,搜狗等多加搜索引擎自动关键词搜索配图,如有侵权的图片,请第一时间联系我们,邮箱:ciyunidc@ciyunshuju.com。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!

    目录[+]