M
M
mazt_ser2021-05-17 15:07:55
Java
mazt_ser, 2021-05-17 15:07:55

How to add your own metrics to prometheus?

I have a class that stores a metric

public static final Counter example_counter = Counter.build()
            .name("example_counter")
            .help("example counter")
            .register();

The following libraries are included:
<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</artifactId>
            <version>0.10.0</version>
        </dependency>

The following has been added to the yaml:
management:
  endpoints:
    web:
      exposure:
        include: health,prometheus
  metrics:
    export:
      prometheus:
        enabled: true
    distribution:
      percentiles-histogram:
        "[http.server.requests]": true

I want that when I make a request to the address localhost:8080/actuator/prometheus , I get not only all the metrics, but also those that I created myself

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question