Reputation: 2661
Followed steps given below to send Metrics from Spring Boot to Prometheus:
Note: I have installed Prometheus locally on my Mac using a Docker image.
In pom.xml added this:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.0.4.RELEASE</version>
</dependency>
<!-- Micormeter core dependecy -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>1.0.6</version>
</dependency>
<!-- Micrometer Prometheus registry -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.0.6</version>
</dependency>
In application.properties added this:
server.port: 9000 management.server.port: 9001 management.server.address: 127.0.0.1 management.endpoint.metrics.enabled=true management.endpoints.web.exposure.include=* management.endpoint.prometheus.enabled=true management.metrics.export.prometheus.enabled=true
Global configurations
global:
scrape_interval: 5s # Set the scrape interval to every 5 seconds.
evaluation_interval: 5s # Evaluate rules every 5 seconds.
scrape_configs:
- job_name: 'hello-world-promethus'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['localhost:9001']
When I hit: http://localhost:9001/actuator/prometheus, I can see the metrics but they are not visible on Prometheus UI.
What am I missing?
Upvotes: 4
Views: 5028
Reputation: 2661
Solution was simple. You will run into this only if you're running Prometheus Docker Container. Changed target from: 'localhost:9001' to 'docker.for.mac.localhost:9001'. For example:
- job_name: hello-world-promethus
scrape_interval: 5s
scrape_timeout: 5s
metrics_path: /actuator/prometheus
scheme: http
static_configs:
- targets:
- docker.for.mac.localhost:9001
Upvotes: 9