2
votes

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.

2

2 Answers

5
votes

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:

  1. install Prometheus Server https://prometheus.io/docs/prometheus/latest/installation/
  2. configure Prometheus to scrape (pull) the metrics from your server. 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)
scrape_configs:
  - job_name: 'mySpringBoot'
    metrics_path: '/manage/prometheus'
    static_configs:
      - targets: ['springBootHost:springBootPort']
  1. once this is configured, go to the Prometheus UI, check that the target is UP - http://localhost:9090/targets (assuming Prometheus runs on localhost)
  2. if you don't see your target or you see it as DOWN there is a configuration or network problem.

the following steps are straight forward, with lot of documentation elsewhere:

  1. next step is to install Grafana
  2. now configure Prometheus as a data-source in Grafana
  3. start plotting your metrics.
0
votes

Spring boot api application configure with prometheus and grafana on windows.

  1. 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.

  1. Download and install Prometheus Server https://prometheus.io/download/ and extract the zip and run prometheus exe.

  2. 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]
  1. once this is configured, go to the Prometheus UI, check that the target is UP - http://localhost:9090/targets (assuming Prometheus runs on localhost)

  2. 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:

  1. next step is to install Grafana from - https://grafana.com/grafana/download?platform=windows and extract the zip and run the grafana-server.exe and check on your browser ‘http://localhost:3000
  2. now login as a default username ‘’admin and password ‘admin’ and go to setting select the deshboard and create a datasource and select prometheus and type url of prometheus like - ‘’http://ipaddress:pord of prometheus.
  3. and go to graph and click edit and select datasource and type your metric query like ‘http_server_request_seconds_max’ 9.start plotting your metrics.