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

Prometheus+Grafana学习(十一)安装使用pushgateway

Pushgateway允许短暂和批量作业将其指标暴露给 Prometheus。由于这些工作的生命周期可能不足够长,不能够存在足够的时间以让 Prometheus 抓取它们的指标。Pushgateway 允许它们可以将其指标推送到 Pushgateway,然后 Pushgateway 再将这些指标暴露给 Prometheus 抓取。

盲目的使用Pushgateway来代替Prometheus常用的拉动模型(pull model)来收集指标,会有以下几种问题:
1.通过单个 Pushgateway 监控多个实例时, Pushgateway 将会成为单点故障和潜在瓶颈
2.当你通过 up 命令(每次擦出时生成),将丢失 Prometheus 自动实例运行状态监控
3.Pushgateway 不会忘记推送时间序列并将永远暴露给 Prometheus,除非这些序列是通过 Pushgateway 的 API 手动删除的

1、下载pushgateway

下载地址:
https://github.com/prometheus/pushgateway/releases/download/v1.5.1/pushgateway-1.5.1.windows-amd64.zip

2、修改prometheus的配置

修改prometheus.yml,添加pushgateway的job

# my global config
global:scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.# scrape_timeout is set to the global default (10s).# Alertmanager configuration
alerting:alertmanagers:- static_configs:- targets:# - alertmanager:9093# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:# - "first_rules.yml"# - "second_rules.yml"# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.- job_name: "prometheus"# metrics_path defaults to '/metrics'# scheme defaults to 'http'.static_configs:- targets: ["localhost:9090"]#  - job_name: "station"
#    metrics_path: /prometheus
#    static_configs:
#      - targets: ["localhost:14501"]- job_name: "pushgateway"honor_labels: truestatic_configs:- targets: ["localhost:9091"]labels:instance: pushgateway

3、启动pushgateway

解压pushgateway
点击pushgateway.exe运行

4、测试推送数据到pushgateway(java)

引入依赖

<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>io.micrometer</groupId><artifactId>micrometer-registry-prometheus</artifactId></dependency><dependency><groupId>io.prometheus</groupId><artifactId>simpleclient_pushgateway</artifactId><version>0.16.0</version></dependency></dependencies>
@Autowired
private CollectorRegistry collectorRegistry;PushGateway pushGateway= new PushGateway("http://localhost:9091");
Guage stationSystemCpuTotal = Gauge.build().name("cpu_total").help("Number of CPU cores on the station.").unit("C").labelNames("a","b").register(collectorRegistry);
stationSystemCpuTotal.labels("A", "B").set(10);  
Map<String, String> groupingKey = new HashMap<>() {{put("collector_name", "cpu");}};
pushGateway.pushAdd(stationSystemCpuTotal , "test-job", groupingKey);

5、查看pushgatway

在这里插入图片描述

6、查看Prometheus

在这里插入图片描述

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

相关文章:

  • 深入理解C/C++预处理器指令#pragma once以及与ifndef的比较
  • git 环境配置 + gitee拉取代码
  • 港联证券|港股拥抱特专科技企业 内资券商“修炼内功”蓄势而为
  • 多项创新技术加持,实现零COGS的Microsoft Editor语法检查器
  • Python编程环境搭建:Windows中如何安装Python
  • Sui Builder House首尔站倒计时!
  • Java设计模式-状态模式
  • 智慧社区用什么技术开发
  • 多线程 线程池饱和策略
  • 进程间通信之信号
  • 二分查找三道题
  • MyBatis 框架
  • 【C++】虚表和虚基表到底有哪些区别?
  • 剑指 Offer 04. 二维数组中的查找解题思路
  • 冯诺依曼体系结构详解
  • ISO证书“带标”与“不带标”的区别是什么?
  • RocketMQ 领域模型概述
  • 黄河千年清一回与人类健康
  • Android java层hook------xposed框架的使用
  • css奇淫巧计
  • Web服务器实现|基于阻塞队列线程池的Http服务器|线程控制|Http协议
  • 【C++】运算符重载(日期类的实现)
  • 【Linux】线程分离 | 线程库 | C++调用线程 | 线程局部存储
  • c++ ffmpeg 浅谈YUV444、YUV422、YUV420(2)
  • Redis在Windows下安装配置教程
  • 数据库服务器
  • VS输出路径和生成事件
  • 从 WebKit 看浏览器内核架构
  • 使用原生的 JavaScript,不依赖于任何特定的库与 ROSBridge进行通信
  • MATLAB第十章_图像处理算法