How to Use spring-boot-starter-actuator Without spring-boot-starter-web for Health Checks and Prometheus Metrics? - Stack Overfl

admin2025-04-18  0

I have two services running in Kubernetes, and I need to configure:

1.  A health check (using httpGet)
2.  Prometheus metrics (via /actuator/prometheus)

My services use either:

•   .springframework.cloud:spring-cloud-stream
•   .springframework.grpc:spring-grpc-spring-boot-starter

I do not use spring-boot-starter-web and would prefer not to add it just for health checks and metrics.

How can I expose actuator endpoints (/actuator/health, /actuator/prometheus) without adding spring-boot-starter-web? Are there alternative ways to achieve this in a lightweight manner?

Thanks in advance! Spring Boot 3.4.3

I have two services running in Kubernetes, and I need to configure:

1.  A health check (using httpGet)
2.  Prometheus metrics (via /actuator/prometheus)

My services use either:

•   .springframework.cloud:spring-cloud-stream
•   .springframework.grpc:spring-grpc-spring-boot-starter

I do not use spring-boot-starter-web and would prefer not to add it just for health checks and metrics.

How can I expose actuator endpoints (/actuator/health, /actuator/prometheus) without adding spring-boot-starter-web? Are there alternative ways to achieve this in a lightweight manner?

Thanks in advance! Spring Boot 3.4.3

Share Improve this question asked Mar 6 at 14:07 Дима ГумановДима Гуманов 1252 silver badges14 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Why not use spring-boot-starter-actuator dependency? That will give you the option of exposing plenty of endpoints.

As for prometheus, you will have to use io.micrometer:micrometer-registry-prometheus dependency in addition to enable /actuator/prometheus. It is plug-and-play so it will start exposing your JVM metrics.

The following config must be added in the base application.yml of the spring-boot service:

management:
  endpoints:
    web:
      exposure:
        include: * # health,prometheus
    health:
      show-details: always

You can be more granular on what endpoints you want to expose by replacing the * with something more specific as per Spring's doco: Endpoints :: Spring Boot

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744970928a277482.html

最新回复(0)