Spring-Boot-Actuator Endpoint Prometheus not shown correctly
Asked Answered
H

8

5

I want to show some metrics using micrometer prometheus in combination with the spring-boot-actuator. My project is totally based on spring-boot and has the actuator feature enabled and mapped on the following url: http://localhost:9000/actuator Other endpoints are shown correctly but the http://localhost:9000/actuator/prometheus isn´t. Below you find a screenshot that I get when accessing this http-endpoint.

Can anybody help me? Why is this happening and how do i fix it? Cause normally prometheus is configured automatically for spring-boot-actuator when you provide the suitable dependency.

Blank space when i try to access the url: http://localhost:9000/actuator/prometheus

Accessing http://localhost:9000/actuator leads to the following and shows that prometheus endpoint is activated and exposed

Hudson answered 29/11, 2021 at 10:57 Comment(4)
Try running your application with the --debug flag (or -Ddebug). From the given information, it seems like some autoconfiguration is not being done. Enabling debug will tell you exactly why (either missing dependency, wrongly configured properties, etc.).Visceral
thanks for the reply but it didnt log out anything usefull, just normal stuff while starting the application, any further ideas?Hudson
Can you please update your question with the prometheus' configuration? Make sure that the metrics_path is configured correctly e.g metrics_path: '/actuator/prometheus'Spada
prometheus configuration? is this necessary? cause i thought there is /actuator/prometheus configured per default can you provide me a example config? would be very helpful=)Hudson
G
6

This is auto-cofigured by default, here are some pointers for troubleshooting:

  • Check if you added micrometer-registry-prometheus (without defining the version, the version should come from the BOM)
  • Check if the actuator endpoint is enabled: management.endpoints.web.exposure.include=*
  • Check if there is a controller that maps the path of the prometheus endpoint or any of its sub-paths (/, /actuator, /actuator/prometheus)
  • Check if you browser tricks you curl localhost:9090/actuator/prometheus
Gotama answered 30/11, 2021 at 4:29 Comment(2)
the only path mapped here is the context path of the application to / but it doenst effect the other endpoints interesting to mention is that the /metrics endpoint shows all metrics but not values for them maybe there is a relation between the 2 problems? but i cannot think of it whyHudson
Thank you. The without defining the version part was what got this working for me.Iambus
M
5

you need to check many things to be sure to enable Prometheus by Actuator

  • First thing you should put the following dependency on your pom.xml to enable Prometheus on your project.

             <!-- enable prometheus-->
         <dependency>
             <groupId>io.micrometer</groupId>
             <artifactId>micrometer-registry-prometheus</artifactId>
             <version>1.10.2</version>
         </dependency>
    
  • The second point you must check if the actuator exists on your project or not if doesn't exist, you need to add the following dependency.

         <!--to enable actuator help to trace project-->
     <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-actuator</artifactId>
     </dependency>
    
  • You need to add the following scripts to your application.yml to enable the actuator and Prometheus by actuator.

.

management:
  security:
    enabled: false
  server:
    port: 9000
  endpoint:
    metrics:
      enabled: true
    prometheus:
      enabled: true
    health:
      show-details: always
      show-components: always
      probes:
        enabled: true
    shutdown:
      enabled: true
    info:
      env:
        enabled: true
      enabled: true
  endpoints:
    web:
      exposure:
        include: prometheus, metrics, info, health, shutdown, beans

using the above script the actuator will run on port 9000 and you can send a request to the following URL to access the actuator.

http://localhost:9000/actuator/prometheus

and the following URL to access Prometheus

http://localhost:9000/actuator/prometheus

Note: you must check where you are writing your script because I was confused between endpoint and endpoints

  • The endpoint to set the actuator config.
  • The endpoints to set the actuator URLs endpoint

Note: you can delete the port from application.yml and the actuator will run by current application port

best luck

Marquettamarquette answered 3/1, 2023 at 19:41 Comment(3)
fyi: the Micrometer team does not recommend defining versions in case you use Spring Boot (or something else that defines Micrometer versions). Also, I'm not sure why you define so many properties in your yaml file when you only need one.Gotama
@JonatanIvanovANd which one is needed?Slope
was missing micrometer-registry-prometheus in my case. Worked now, thanksSabaean
T
0

to me , this did the trick, with everything else enabled ( endpoints and metrics ) but without this, /actuactor/prometheus was not exposed

management:
  metrics: 
    export:
      prometheus:
        enabled: true


Traynor answered 20/7, 2023 at 15:4 Comment(0)
S
0

I had to enable the following property (Spring Boot 3.1.x) with everything else enabled.

management.prometheus.metrics.export.enabled=true

management.metrics.export.prometheus.enabled is deprecated according to IntelliJ

Salahi answered 30/5 at 18:32 Comment(0)
M
0

I found that when I went to http://localhost:9999/actuator that I did not have prometheus showing up. I tried all the different configs, but my issue turned out to be a missing dependency

    <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-tracing-bridge-brave</artifactId>
    </dependency>

So I had the standard io:micrometer:micrometer-registry-prometheus, the applicaiton.property configs, and then this dependency.

Musketeer answered 22/8 at 20:30 Comment(0)
V
0

If someone still facing issue try adding this dependency : implementation group: 'io.micrometer', name: 'micrometer-registry-prometheus-simpleclient', version: '1.13.5' it worked for me

Vex answered 11/10 at 16:8 Comment(0)
H
-1

ok i solved it with the solution:

i created a bean of type prometheusMeterRegistry manually and so spring boot didn't configure it automatically leading to no metrics provided at the prometheus endpoint see below code snippet for further details:

// @Bean
// public PrometheusMeterRegistry prometheusMeterRegistry() {
//  return new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
// }
Hudson answered 1/12, 2021 at 11:21 Comment(4)
fyi: this is only hiding the real problem, Spring Boot autoconfigures this, check if you have spring-boot-actuator and the versions are matching.Gotama
which versions do you mean? all spring boot versions are checked and consistent and just updated to spring-boot 2.6 and used the matching version of prometheus for thisHudson
You need to add org.springframework.boot:spring-boot-starter-actuator and io.micrometer:micrometer-registry-prometheus, no version, the version should come from the BOM. The Spring Boot auto-config must create a PrometheusMeterRegistry for you (registered in a composite). If it does not, please create an issue for Spring Boot.Gotama
I think here is the bug lurking somethere. Because I have the same issue with Spring Boot 2.6. Actuator just ingnore Prometheus existanceClactonian
L
-1

In my case I was trying to set up prometheus on old project where was MetricsAutoConfiguration excluded. So removing exclude solved the problem.

@EnableAutoConfiguration(exclude = { MetricsAutoConfiguration.class})
Lothario answered 30/9, 2022 at 12:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.