update 优化 prometheus sd发现 兼容携带context-path的服务

This commit is contained in:
疯狂的狮子Li
2024-12-05 16:32:50 +08:00
parent 1b34b99a75
commit f890ad4246
2 changed files with 9 additions and 0 deletions

View File

@@ -45,6 +45,10 @@ public class PrometheusController {
// labels.put("__meta_datacenter", "beijing");
// 服务名
labels.put("__meta_prometheus_job", service);
String contextPath = instances.get(0).getMetadata().get("management.context-path");
if (contextPath != null) {
labels.put("__meta_http_sd_context_path", contextPath.replaceAll("/actuator", ""));
}
Map<String, Object> group = new HashMap<>(2);
group.put("targets", targets);
group.put("labels", labels);