简体   繁体   English

在 Spring Boot 和 Prometheus 中监控自定义指标

[英]Monitor custom metrics in Spring Boot and Prometheus

I want to send some metrics, such as ResponseTime, RequestCount, etc. to Prometheus and then define a dashboard on Grafana.我想向 Prometheus 发送一些指标,例如 ResponseTime、RequestCount 等,然后在 Grafana 上定义一个仪表板。 I know that I have to autowire PrometheusMeterRegistry in our class and use that as shown in the following:我知道我必须在我们的类中自动装配PrometheusMeterRegistry并使用它,如下所示:

@Autowired
private PrometheusMeterRegistry registry;

public void addSuccess(){
    registry.counter("RequestCountMetric", "success").increment()
}

Now, I don't know how to set up the Prometheus ip/port in our Spring Boot application.现在,我不知道如何在我们的 Spring Boot 应用程序中设置 Prometheus ip/port。

Prometheus uses a pull/scrape model meaning that instead of that the Spring Boot application sends metrics to a monitoring system, eg over and UDP utilizing statsD, Prometheus will call an endpoint exposes by the application to pull the metrics. Prometheus 使用pull/scrape模型,这意味着 Spring Boot 应用程序不会将指标发送到监控系统,例如使用 statsD 和 UDP,Prometheus 将调用应用程序公开的端点以提取指标。

Add prometheus to your exposed actuator endpoints in your application.properties in order to open up the endpoint /actuator/prometheus :prometheus添加到application.properties中暴露的执行器端点,以打开端点/actuator/prometheus

management.endpoints.web.exposure.include=prometheus

So, you actually need to configure your Prometheus instance where it can find the Spring Boot application.因此,您实际上需要配置您的 Prometheus 实例,它可以在其中找到 Spring Boot 应用程序。

Here is an example of the Prometheus config pointing to a local Spring Boot application:这是一个指向本地 Spring Boot 应用程序的 Prometheus 配置示例:

global:
  scrape_interval:     15s
  evaluation_interval: 15s

  - job_name: 'my-application to scrape'
    metrics_path: '/actuator/prometheus'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:8080']

Last step is to point your Grafana to your Prometheus which can easily be done in the Grafana UI and add the Prometheus datasource.最后一步是将您的 Grafana 指向您的 Prometheus,这可以在 Grafana UI 中轻松完成并添加 Prometheus 数据源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 普罗米修斯端点中缺少 Spring Boot Webclient 指标 - Spring Boot Webclient metrics missing in prometheus endpoint Spring Boot中的指标未在Prometheus中显示 - Metrics from Spring Boot are not showing up in Prometheus 如何在 Spring Boot for prometheus 中制作自己的指标 - How to make own metrics in Spring Boot for prometheus 从 Spring Boot 应用程序为 Prometheus 生成指标 - Generating metrics for Prometheus from Spring Boot application 使用 Prometheus 监控 Kubernetes 集群中的 Spring Boot 应用 - Using Prometheus to monitor Spring Boot Applications in Kubernetes Cluster 执行器普罗米修斯的自定义指标 - Custom Metrics for Actuator Prometheus 您如何配置prometheus.yml文件以在Spring-Boot应用程序中收集Prometheus指标? - How do you configure prometheus.yml file to collect Prometheus metrics in a Spring-Boot application? Java Spring Boot Prometheus 指标添加 log4j2_events_total 指标 - Java Spring Boot Prometheus metrics adding log4j2_events_total metric 为什么 Spring Boot 执行器具有点分隔的普罗米修斯指标名称? - Why does Spring Boot actuator have dot separated prometheus metrics names? 我如何向普罗米修斯报告 Kafka Producer 的指标(使用 spring boot) - How can I Report Kafka Producer's metrics to prometheus(using spring boot)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM