Метрики от Spring Boot не отображаются в Prometheus - PullRequest
0 голосов
/ 10 сентября 2018

Выполнены следующие шаги для отправки метрик из Spring Boot в Prometheus:

Примечание : я установил Prometheus локально на моем Mac с помощью образа Docker.

  1. В pom.xml добавлено это:

    <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>
    
  2. В application.properties добавлено это:

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:
  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']

Когда я нажимаю: http://localhost:9001/actuator/prometheus, Я вижу метрики, но онине отображается в интерфейсе Prometheus.

Чего мне не хватает?

1 Ответ

0 голосов
/ 10 сентября 2018

Решение было простым. Вы столкнетесь с этим, только если вы используете Prometheus Docker Container. Цель изменена с: «localhost: 9001» на «docker.for.mac.localhost: 9001». Например:

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