Spring Boot Actuator Monitoring Configuration Guide
Spring Actuator
How to collect basic data from Spring into Prometheus
Enabling Actuator in Spring
Add the following to your main program's Maven configuration:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Note the registry version should be compatible with your Spring Boot version, otherwise registration may fail -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
This will automatically expose the corresponding metrics. If you need the Java program to actively push monitoring data, additional configuration is required:
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>prometheus-metrics-exporter-pushgateway</artifactId>
</dependency>
Access Control Exemption
In Spring, you need to configure the properties version:
management.endpoints.web.exposure.include=prometheus
For YAML, configure:
management:
endpoints:
web:
exposure:
include: prometheus
If you have authentication rules, avoid being intercepted by access control. Please exempt /actuator/prometheus
data access.
Accessing Prometheus Data Endpoints in Spring
# View all HTTP request metrics
curl http://localhost:8080/actuator/metrics/http.server.requests
# View the duration of a specific API
curl "http://localhost:8080/actuator/metrics/http.server.requests?tag=uri:/api/agvLocation/query.json"
Prometheus Collection Configuration
- job_name: 'springboot-app1'
metrics_path: '/actuator/prometheus'
scrape_interval: 30s
static_configs:
- targets:
- '127.0.0.1:8080'
labels:
app: 'springboot-app1'
env: 'prod'
Grafana Monitoring Dashboard Template
https://grafana.com/grafana/dashboards/4701-jvm-micrometer/
Core Metric Explanations
In general, we focus on http_xxx metrics as they are closely related to users.
1. JVM Related Metrics
jvm_memory_used_bytes
JVM memory used in bytes, helping monitor memory consumption and memory leak risks.jvm_memory_max_bytes
Maximum memory that JVM can allocate, monitoring whether it's approaching the memory limit.jvm_threads_live
Current number of live threads, monitoring thread leaks and blocking issues.jvm_gc_pause_seconds_count / sum
GC pause count and total duration, evaluating the impact of garbage collection on application performance.
2. System Resource Metrics
process_cpu_usage
CPU usage of the application process, reflecting application load.process_uptime_seconds
Application uptime, determining if the service is restarting frequently.system_cpu_usage
Overall CPU usage of the host or container.
3. HTTP Request Related Metrics
http_server_requests_seconds_count
Total number of HTTP requests, reflecting business traffic.http_server_requests_seconds_sum
Total request duration, combined with count to calculate average response time.http_server_requests_seconds_max
Maximum request duration, monitoring slow interfaces.http_server_requests_active
Number of requests currently being processed, judging interface pressure.
4. Database Connection Pool Metrics (using HikariCP as an example)
hikaricp_connections_active
Current number of active database connections.hikaricp_connections_max
Maximum available database connections.hikaricp_connections_pending
Number of requests waiting to acquire database connections, reflecting database pressure.
5. Tomcat Related Metrics (if using Tomcat)
tomcat_threads_current
Current number of Tomcat threads.tomcat_threads_busy
Current number of busy threads.tomcat_sessions_active_current
Current number of active sessions.