Spring Boot Actuator + Micrometer export metric sang Prometheus → Grafana visualize.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>management:
endpoints.web.exposure.include: health, info, prometheus
metrics:
tags:
application: ${spring.application.name} # label chung cho mọi metricCustom metrics:
@Component
class OrderMetrics {
private final Counter orderCreated;
private final Timer orderProcessingTime;
OrderMetrics(MeterRegistry registry) {
orderCreated = Counter.builder("orders.created")
.description("Total orders created")
.register(registry);
orderProcessingTime = Timer.builder("orders.processing.time")
.register(registry);
}
public void recordOrder(Runnable task) {
orderCreated.increment();
orderProcessingTime.record(task);
}
}Prometheus scrape config: thêm job metrics_path: /actuator/prometheus trong prometheus.yml, target app:8080.
Built-in metrics: JVM memory/GC, Tomcat threads, DB connection pool (HikariCP), HTTP request count/latency, cache hit rate.
Grafana: import dashboard "Spring Boot Statistics" để có sẵn overview JVM, HTTP, HikariCP.
Spring Boot Actuator + Micrometer exports metrics to Prometheus → Grafana visualises them.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>management:
endpoints.web.exposure.include: health, info, prometheus
metrics:
tags:
application: ${spring.application.name} # common label for all metricsCustom metrics:
@Component
class OrderMetrics {
private final Counter orderCreated;
private final Timer orderProcessingTime;
OrderMetrics(MeterRegistry registry) {
orderCreated = Counter.builder("orders.created")
.description("Total orders created")
.register(registry);
orderProcessingTime = Timer.builder("orders.processing.time")
.register(registry);
}
}Prometheus scrape config: add a job with metrics_path: /actuator/prometheus targeting app:8080 in prometheus.yml.
Built-in metrics: JVM memory/GC, Tomcat threads, DB connection pool (HikariCP), HTTP request count/latency, cache hit rate.
Grafana: import the "Spring Boot Statistics" dashboard for a ready-made overview of JVM, HTTP, and HikariCP metrics.