要在Spring Boot項目中使用Prometheus進行監控,需要進行以下步驟:
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
management:
endpoints:
web:
exposure:
include: prometheus
@SpringBootApplication
@EnablePrometheusEndpoint
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
scrape_configs:
- job_name: 'spring-boot-app'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['localhost:8080']
通過以上步驟,您就可以在Spring Boot應用程序中使用Prometheus進行監控。希望對您有所幫助!