How to Add Prometheus to a Spring Boot Application
1. Introduction .......................................................................................................... 1
2. Add Required Dependencies (Maven) ...................................................................... 1
3. Add Required Dependencies (Gradle) ..................................................................... 1
4. Configure [Link] ............................................................................ 2
5. Verify the Prometheus Endpoint.............................................................................. 2
6. Configure Prometheus Server (For Locally) .............................................................. 2
7. Start Prometheus .................................................................................................. 3
1. Introduction
Prometheus is an open-source monitoring and alerting toolkit commonly
used with Spring Boot applications. In Spring Boot, Prometheus integration is
typically done using Spring Boot Actuator and Micrometer.
2. Add Required Dependencies (Maven)
Add the following dependencies to your [Link] file:
<dependencies>
<!-- Spring Boot Actuator -->
<dependency>
<groupId>[Link]</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Prometheus Registry -->
<dependency>
<groupId>[Link]</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
</dependencies>
3. Add Required Dependencies (Gradle)
For Gradle users, add the following to [Link]:
implementation '[Link]:spring-boot-starter-actuator'
implementation '[Link]:micrometer-registry-prometheus'
4. Configure [Link]
Add the following configuration to [Link]:
[Link]=health,info,metrics,prometheus
[Link]=true
[Link]=true
[Link]=true
[Link]=true
[Link]=true
[Link]=true
[Link]=${[Link]}
[Link]-path=/actuator
5. Verify the Prometheus Endpoint
Run your Spring Boot application and access:
[Link]
6. Configure Prometheus Server (For Locally)
Download and install Prometheus.
Edit [Link]:
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'spring-boot-app'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['localhost:8080']
7. Start Prometheus
Run:
prometheus --[Link]=[Link]
Open Prometheus UI:
[Link]
You can now query metrics like:
http_server_requests_seconds_count
jvm_memory_used_bytes