Home > Net >  How to include timestamps in Spring Boot Actuator Prometheus metrics
How to include timestamps in Spring Boot Actuator Prometheus metrics

Time:10-14

I am using Spring Boot 2.5.4 and Actuator with Micrometer and Prometheus support. When I open the /actuator/prometheus endpoint, I see metrics like these:

# HELP jvm_threads_live_threads The current number of live threads including both daemon and non-daemon threads
# TYPE jvm_threads_live_threads gauge
jvm_threads_live_threads 28.0

Note that there is no timestamp attached to that metric. However, according to OpenMetrics / Prometheus spec, it is possible to add a timestamp to the metrics output.

My question: How can you tell Spring Boot Actuator to generate and add a timestamp to the metrics it creates? I have not found any documentation on it. Thanks!

References

My pom.xml dependencies look like this:

     <dependency>
      <groupId>io.micrometer</groupId>
      <artifactId>micrometer-core</artifactId>
    </dependency>

    <dependency>
      <groupId>io.micrometer</groupId>
      <artifactId>micrometer-registry-prometheus</artifactId>
    </dependency>

My application.yaml like this:


# Application name. Shows up in metrics etc.
spring:
  application:
    name: "some_app_name"

# Expose application on port 8080
server:
  port: ${SERVER_PORT:8080}

# Expose all Actuator endpoints (don't do this in production!)
management:
  endpoints:
    web:
      exposure:
        include:
        - "*"

CodePudding user response:

Micrometer doesn't support this at the moment. The team's recommendation is to use the Prometheus Java Client directly for metrics where the timestamp is important to you.

  • Related