Custom Actuator Endpoint and Prometheus Exposition
Fast recall
Quick revision
Core answer
@Endpoint(id = "name") and methods annotated @ReadOperation, @WriteOperation, or @DeleteOperation — Spring Boot exposes them at /actuator/name automatically. Register the bean and add the ID to management.endpoints.web.exposure.include. For Prometheus, add micrometer-registry-prometheus and Spring Boot auto-configures /actuator/prometheus returning OpenMetrics-format text. Inject MeterRegistry to publish custom metrics: counters, gauges, timers, distribution summaries. Always tag metrics with bounded label sets — high-cardinality tags (user IDs, request IDs) explode Prometheus storage and become operationally unmanageable.Whether you can implement custom Actuator extension points and integrate Spring Boot metrics into a Prometheus monitoring pipeline
Tagging metrics with unbounded values (user IDs, URL paths with IDs), causing Prometheus cardinality explosion and OOM in the time-series database
Mention `MeterFilter` for cardinality limits, `@Timed` annotation for declarative timer instrumentation, and the difference between Counter/Gauge/Timer/DistributionSummary metric types
Interview-ready guide
Interview answer
Spring Boot Actuator has two extension points: custom endpoints for app-specific operational data and custom metrics through Micrometer for everything that's quantitative.
Custom endpoints
- Annotate a Spring bean with
@Endpoint(id = "features") - Add
@ReadOperation,@WriteOperation,@DeleteOperationmethods @Selectorcaptures path variables:/actuator/features/{name}- Register by adding the ID to
management.endpoints.web.exposure.include - Same Spring Security rules apply as built-in endpoints
Custom metrics
- Inject
MeterRegistry; createCounter,Gauge,Timer, orDistributionSummary - Use
@Timedfor declarative method timing — needs aTimedAspectbean - Add
micrometer-registry-prometheusand Spring Boot auto-configures/actuator/prometheus - Output is OpenMetrics text; Prometheus scrapes it on a configured interval
Cardinality is the trap
- Never tag metrics with unbounded values: user ID, request ID, URL path with IDs
- A
Countertagged with user ID becomes one time series per user — millions of series, Prometheus OOM - Use
MeterFilter.maximumAllowableTagsto cap tag cardinality - Bounded tags are fine: region, HTTP method, status code, error class
In an interview, I'd close with the operational rule: measure first, instrument second. Spring Boot already publishes HTTP latency, JVM memory, JDBC pool stats, and Tomcat thread counts through Micrometer — no custom code needed. Add custom metrics only for KPIs the framework doesn't already cover.
Custom Actuator Endpoint and Prometheus Exposition
Direct Answer
Create a custom Actuator endpoint with @Endpoint(id = "name") and methods annotated @ReadOperation, @WriteOperation, or @DeleteOperation — Spring Boot exposes them at /actuator/name automatically. Register the bean and add the ID to management.endpoints.web.exposure.include. For Prometheus, add micrometer-registry-prometheus and Spring Boot auto-configures /actuator/prometheus returning OpenMetrics-format text. Inject MeterRegistry to publish custom metrics: counters, gauges, timers, distribution summaries. Always tag metrics with bounded label sets — high-cardinality tags (user IDs, request IDs) explode Prometheus storage and become operationally unmanageable.
Common Mistakes & Pitfalls
Tagging metrics with unbounded values (user IDs, URL paths with IDs), causing Prometheus cardinality explosion and OOM in the time-series database
Check your understanding
Answer these without looking back at the article.
- How would you implement a `MeterFilter` that drops metrics with more than 100 tag values?
- Why should you use `rate()` rather than raw counter values in PromQL queries?
- How does `@Timed` differ from manually recording with `Timer.record()`?
- What is a `LongTaskTimer` and when would you use it instead of a regular `Timer`?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.