mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-10-14 14:10:24 +00:00
update 优化 prometheus sd发现 兼容携带context-path的服务
This commit is contained in:
@@ -52,3 +52,8 @@ scrape_configs:
|
||||
basic_auth:
|
||||
username: ruoyi
|
||||
password: 123456
|
||||
relabel_configs:
|
||||
# 如果目标有context_path标签,则修改metrics_path以包含该上下文路径
|
||||
- source_labels: [__meta_http_sd_context_path]
|
||||
target_label: __metrics_path__
|
||||
replacement: '${1}/actuator/prometheus'
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user