custom path for prometheus actuator

心不动则不痛 提交于 2019-12-07 04:10:15

问题


I am currently trying to migrate our prometheus lib to spring boot 2.0.3.RELEASE. We use a custom path for prometheus and so far we use a work around to ensure this. As there is the possibility for a custom path for the info- and health-endpoint, uses management.endpoint.<health/info>.path. I tried to specify management.endpoint.prometheus.path, but it was still just accessible under /actuator/prometheus.

How can I use a custom path or prometheus?

We enable prometheus using the following libs (snippet of our build.gradle)

compile "org.springframework.boot:spring-boot-starter-actuator:2.0.3.RELEASE"
compile "io.micrometer:micrometer-core:2.0.5"
compile "io.micrometer:micrometer-registry-prometheus:2.0.5"

we also use the import of the class PrometheusMetricsExportAutoConfiguration

Your help is highly appreciated :)


回答1:


From the reference documentation:

By default, endpoints are exposed over HTTP under the /actuator path by using the ID of the endpoint. For example, the beans endpoint is exposed under /actuator/beans. If you want to map endpoints to a different path, you can use the management.endpoints.web.path-mapping property. Also, if you want change the base path, you can use management.endpoints.web.base-path.

The following example remaps /actuator/health to /healthcheck:

application.properties:

management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.health=healthcheck

So, to remap the prometheus endpoint to a different path beneath /actuator you can use the following property:

management.endpoints.web.path-mapping.prometheus=whatever-you-want

The above will make the Prometheus endpoint available at /actuator/whatever-you-want

If you want the Prometheus endpoint to be available at the root, you'll have to move all the endpoints there and remap it:

management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.prometheus=whatever-you-want

The above will make the Prometheus endpoint available at /whatever-you-want but with the side-effect of also moving any other enabled endpoints up to / rather than being beneath /actuator.



来源:https://stackoverflow.com/questions/51195237/custom-path-for-prometheus-actuator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!