[英]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.