背景:SpringBoot2的項目要配置 actuator + prometheus的健康檢查,按照教程配置好之后再瀏覽器測試 http://localhost:port/prometheus 后404錯誤
項目pom文件添加;
<!--actuator--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> <version>2.0.1.RELEASE</version> </dependency> <!--pometheus 監控--> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> <version>1.0.3</version> </dependency>
springboot2的配置文件application.properties添加
management.endpoints.enabled-by-default=true
management.endpoints.web.exposure.include="*"
management.endpoints.web.base-path=/
management.endpoints.jmx.exposure.include="*"
management.endpoints.jmx.shutdown.enabled=false
management.endpoints.metrics.export.prometheus.enabled=true
management.endpoints.metrics.distribution.percentiles-histogram[http.server.requests]=true
management.endpoints.security.enabled=false
management.endpoint.health.show-details=always
然后啟動項目發現
問題解決:
*號在yaml文件中屬於關健字,所以要加引號,但是再properties文件中就不能加引號
項目改成多模塊應用后,prometheus又發生了404錯誤。經過排查,是根目錄的pom.xml中prometheus配置的不對
錯誤的配置: 不能夠配置到<dependencyManagement>標簽中
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> <version>2.0.1.RELEASE</version> </dependency> <!--pometheus 監控--> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> <version>1.0.3</version> </dependency> </dependencies> </dependencyManagement>
正確的配置:
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> <version>2.0.1.RELEASE</version> </dependency> <!--pometheus 監控--> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> <version>1.0.3</version> </dependency> </dependencies>