Monitoring Spring Boot Tomcat Metrics with Actuator and Prometheus
This article explains how to use Spring Boot Actuator to expose Tomcat performance metrics, retrieve health and metric endpoints via HTTP, configure custom endpoints, and optionally log or export the data to Prometheus for continuous monitoring and analysis.
Spring Boot greatly speeds up web service development with its embedded container, but the gateway layer—being the entry point for user requests—often becomes a performance bottleneck that requires careful tuning.
The Spring Boot Actuator module provides built‑in endpoints for monitoring application health, thread usage, and other runtime information.
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>After the application starts, Actuator exposes HTTP endpoints under http://{application}/actuator. The default endpoints include /actuator/info and /actuator/health.
The base path can be changed with the property: management.endpoints.web.base-path=/mypath Example to query health status:
$ curl 'http://localhost:8080/actuator/health' -i -X GETTypical response:
{
"status" : "UP"
}To obtain more detailed health data, enable the property: management.endpoint.health.show-details=always Resulting JSON may include Redis and disk‑space details.
For deeper container metrics, the /actuator/metric endpoint must be exposed:
# Enable metric endpoint
management.endpoints.web.exposure.include=info,health,metricCalling the metric endpoint lists all available metric names, such as:
"tomcat.threads.config.max"
"tomcat.threads.current"
"tomcat.threads.busy"Specific values are retrieved by appending the metric name, e.g.:
$ curl 'http://localhost:8080/actuator/metric/tomcat.threads.busy' {
"name":"tomcat.threads.busy",
"measurements":[{"statistic":"VALUE","value":1.0}],
"availableTags":[{"tag":"name","values":["http-nio-10610"]}]
}During traffic spikes, these real‑time metrics help pinpoint performance issues. For historical analysis, a service can periodically scrape the metrics; Spring Boot offers a Prometheus exporter for this purpose (see https://www.callicoder.com/spring-boot-actuator-metrics-monitoring-dashboard-prometheus-grafana/).
Alternatively, metrics can be logged at regular intervals using a LoggingMeterRegistry bean:
@Configuration
class MetricsConfig {
@Bean
LoggingMeterRegistry loggingMeterRegistry() {
return new LoggingMeterRegistry();
}
}The required LoggingMeterRegistry class is part of micrometer‑core version 1.10+. If using Spring Boot 1.x, add the dependency manually:
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>1.1.3</version>
</dependency>Log output (default every minute) includes JVM buffers, memory usage, thread states, and Tomcat thread metrics such as:
tomcat.threads.busy{name=http-nio-10610} value=0 threads
tomcat.threads.config.max{name=http-nio-10610} value=200 threads
tomcat.threads.current{name=http-nio-10610} value=10 threadsTo change the logging frequency, customize the LoggingRegistryConfig:
return new LoggingMeterRegistry(new LoggingRegistryConfig() {
@Override
public Duration step() { return Duration.ofSeconds(10); } // every 10 seconds
@Override
public String get(String key) { return null; }
}, Clock.SYSTEM);Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Selected Java Interview Questions
A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
