按照以下步骤将指标从 Spring Boot 发送到 Prometheus:注意:我已经使用 Docker 映像在我的 Mac 上本地安装了 Prometheus。在 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>在 application.properties 中添加了这个:server.port: 9000management.server.port: 9001management.server.address: 127.0.0.1management.endpoint.metrics.enabled=truemanagement.endpoints.web.exposure.include=*management.endpoint.prometheus.enabled=truemanagement.metrics.export.prometheus.enabled=true在配置文件中使用以下几行启动 Prometheus:全局配置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 UI 上不可见。我错过了什么?
1 回答
catspeake
TA贡献1111条经验 获得超0个赞
解决方案很简单。只有在运行 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
添加回答
举报
0/150
提交
取消