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

news/2025/2/19 9:59:13/

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.ppmy.cn/news/78861.html

相关文章

Linux基本指令介绍

目录 前言 指令操作与图形化界面的对比 adduser passwd whoami ls指令 pwd指令 cd指令 touch指令 mkdir指令 rmdir指令 && rm 指令 man指令 cp指令 mv指令 cat&#xff08;显示文件内容&#xff08;全部&#xff09;&#xff0c;且不可修改的&#xff09;…

关于字符集

字符集 编码与解码 计算机中储存的信息都是用二进制数表示的&#xff0c;而我们在屏幕上看到的数字、英文、标点符号、汉字等字符是二进制数转换之后的结果。按照某种规则&#xff0c;将字符存储到计算机中&#xff0c;称为编码 。反之&#xff0c;将存储在计算机中的二进制数…

C++设计模式介绍与分类

目录 一、设计模式定义 二、设计模式的优点 三、设计模式缺点 四、设计模式中的抽象思维 五、抽象的方法 六、设计模式应用场景 七、设计模式分类 附加知识 &#xff08;1&#xff09;C面向对象三种访问修饰符 &#xff08;2&#xff09;父类析构函数必须为虚函数 &…

Docker(1)

一)什么是虚拟化&#xff1f;容器化&#xff1f; 1)物理机:实际的服务器或者计算机&#xff0c;相对于虚拟机而言的对实体计算机的称呼。物理 机提供给虚拟机以硬件环境&#xff0c;有时也称为“寄主”或“宿主&#xff1b; 2)虚拟化:是指通过虚拟化技术将一台计算机虚拟为多台…

Kafka实时数据同步

目录 1 概述 2 捕获Oracle数据到Kafka 2.1 数据捕获设置 2.2 数据发布设置 2.3 捕获到发布数据流映射 2.4 查看任务执行日志 3 订阅Kafka数据到ClickHouse 3.1 数据订阅设置 3.2 数据加载设置 3.3 订阅到加载数据流映射 3.4 查看任务执行日志 4 校验数据一致性 1 概…

Hadoop部署本地模式

​ 本地模式&#xff0c;即运行在单台机器上。没有分布式的思想&#xff0c;使用的是本地文件系统。使用本地模式主要是用于对MapReduce的程序的逻辑进行调试&#xff0c;确保程序的正确性。由于在本地模式下测试和调试MapReduce程序较为方便&#xff0c;因此&#xff0c;这种模…

多体动力学:哈密尔顿原理的使用

参考资料&#xff1a; HAMILTON’S PRINCIPLE AND HAMILTON’S FORMULATION 原理已经讲得很详细了。如果看不到可以见我的资源&#xff0c;不用积分就可以下载。 步骤&#xff1a; 1.写出拉格朗日表达式 L T − V LT-V LT−V, T T T是系统的动能&#xff0c; V V V是系统的…

Grpc 整合 Nacos SpringBoot 日常使用(Java版本)包括 Jwt 认证

前言 最近感到有点子迷茫&#xff0c;天天写业务代码有点麻木&#xff0c;趁着有点空闲时间去了解了下 Grpc 这个框架&#xff0c;一方面是听说他很火&#xff0c;支持多种语言。另一方面也是为了将来可能需要用到他&#xff0c;未雨绸缪一下&#xff0c;当然了本文只是基于使用…