twinformatics / eureka-consul-adapter

This project contains a Spring Boot Starter that registers HTTP endpoints on a Spring Cloud Eureka server to support Prometheus's service discovery mechanism for Consul (<consul_sd_config>)
MIT License
103 stars 35 forks source link

monitor with contextpath #18

Closed kukuxiahuni closed 5 years ago

kukuxiahuni commented 5 years ago

if spring boot service have servlet.contextPath and managed by eureka, how to config it in prometheus.yml?

tine2k commented 5 years ago

If you want to explicitly set the base path for all services with the sd mechanism, you can just hardcode it in prometheus.yml like so: metrics_path: /mybasepath/actuator/prometheus.

If you have a different base path for each service, you need to send the base path along with the eureka discovery registration (see https://projects.spring.io/spring-cloud/spring-cloud.html#_eureka_metadata_for_instances_and_clients). As soon as it is available in eureka, prometheus will get this metadata (as something like __meta_consulmetadata...). Based on this, you can use the relabeling feature of prometheus to set the correct metrics path for the service (see https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config).