@filiberto
To add Prometheus and Grafana to a Spring Boot application, you can follow these steps:
- Add Prometheus dependencies to your Spring Boot application by adding the following dependency to your pom.xml file:
1
2
3
4
|
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
|
- Configure Prometheus by adding the following properties to your application.properties file:
1
2
|
management.endpoints.web.exposure.include=*
management.metrics.export.prometheus.enabled=true
|
- Add a Prometheus endpoint by adding the following annotation to your main Spring Boot application class:
1
2
3
4
5
6
7
|
@SpringBootApplication
@EnablePrometheusEndpoint
public class YourApplication {
public static void main(String[] args) {
SpringApplication.run(YourApplication.class, args);
}
}
|
- Install Grafana on your machine and start the Grafana server.
- Set up Grafana to connect to Prometheus by adding a Prometheus data source in Grafana. Configure the data source with the URL of your Prometheus server (e.g. http://localhost:9090) and save the configuration.
- Create dashboards in Grafana to visualize the metrics collected by Prometheus. You can create custom dashboards to monitor different aspects of your Spring Boot application.
By following these steps, you can add Prometheus and Grafana to your Spring Boot application and monitor its performance and health in real-time.