Reputation: 111
I am using spring boot 2.0 and added the below dependencies in POM
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
My application.yml looks like this
management.endpoints.web.base-path = /manage
management.endpoints.web.exposure.include = "*"
endpoints.prometheus.enabled = true
when I access Prometheus at
localhost/manage/prometheus
I am able to see all the metrics.
Next, my target is to see the above metrics in Prometheus UI. For this, I added the below dependencies in my POM
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_spring_boot</artifactId>
<version>${prometheus.version}</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_hotspot</artifactId>
<version>${prometheus.version}</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_servlet</artifactId>
<version>${prometheus.version}</version>
</dependency>
What are the next steps for me to see metrics in Prometheus UI, final target is to integrate Prometheus to Grafana.
PS: I did a search on google and tried adding prometheus.yml and adding annotations like @EnablePrometheusEndpoint nothing worked as all the articles are old.
Edit : Also how to configure prometheus.yml ( metrics_path, targets)if the spring boot jar is hosted in different host (Azure/AWS) and prometheus server is in different host.
Upvotes: 3
Views: 1660
Reputation: 697
Spring boot api application configure with prometheus and grafana on windows.
- Create spring boot application and add dependency in pom.xml -
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
if its running go to your browser and type ‘http://localhost:8080/actuator/prometheus’ and you will get all metrics.
Download and install Prometheus Server https://prometheus.io/download/ and extract the zip and run prometheus exe.
for that you will need to modify the prometheus.yml file by adding a new job (don't forget to restart Prometheus after changing the yml file)
Note : configure spring application with prometheus.
scrape_configs: - job_name: 'SpringBootApplicationName metrics_path: ‘actuator-prometheus' static_configs: - targets: [‘IPADDRESS:springBootApplicationPort]
once this is configured, go to the Prometheus UI, check that the target is UP
- http://localhost:9090/targets (assuming Prometheus runs on localhost)
go to ‘http://localhost:8080/actuator/prometheus’ and select one metrics and paste in - http://localhost:9090/graph and click on execute. example you can select one CPU and HTTP metric like - ‘http_server_request_seconds_max’
the following steps are straight forward, with lot of documentation elsewhere:
Upvotes: 0
Reputation: 1301
If you are using Spring Boot 2 and micrometer you don't need to add the extra dependencies, they are imported when you added micrometer-registry-prometheus
. if you are able to see the metrics on localhost/manage/prometheus your configuration on the spring-boot side is fine. there is no need to configure anything more.
To see the metrics in Prometheus you need:
scrape_configs: - job_name: 'mySpringBoot' metrics_path: '/manage/prometheus' static_configs: - targets: ['springBootHost:springBootPort']
UP
- http://localhost:9090/targets (assuming Prometheus runs on localhost)DOWN
there is a configuration or network problem.the following steps are straight forward, with lot of documentation elsewhere:
Upvotes: 5