我终于搞清楚了。下面是一个工作实例。作为 文件 指定,地址关键字可能不适用于所有设置 - 您可能想要尝试“< __ meta_consul_address>:< __ meta_consul_service_port>”代替。
- source_labels: ['__address__'] separator: ':' regex: '(.*):(8300)' target_label: '__address__' replacement: '${1}:9126'
如果您想通过附加注释动态定义端口,即:
selector: matchLabels: app: my-service template: metadata: labels: app: my-service annotations: prometheus: "true" prometheus/port: "8888"
您可以使用以下转换:
- source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_port] action: replace regex: ([^:]+)(?::\d+)?;(\d+) replacement: ${1}:${2} target_label: __address__
普罗米修斯的来源标签与之相结合 ; 在这种情况下,我们将有ie。 (如果你的服务器默认监听8080): http://10.52.9.79:8080;8888
;
http://10.52.9.79:8080;8888
在正则表达式中我们有:
:
//10.52.9.79
因此,您可以从注释中设置原始地址和端口。如果您有Spring Boot应用程序并且希望使用与默认应用程序端口不同的管理端口,则可能很有用。