我正在尝试向Prometheus中的目标添加一个标签,以修改SpringBoot中的文件。
我尝试在Springboot中添加一个Prometheus标签,方法如下(在SpringBoot中修改SpringBoot中的Prometheus),但没有成功。
management:
metrics:
tags:
application: ${spring.application.name}
threadLimitInPrometheus: 40 # This tag didn't work您能告诉我在SpringBoot中添加Prometheus标签的方法吗?
我知道有一种方法可以向目标添加一个新标签,按照下面的方式修改prometheus.yml
- target_label: "foo"
replacement: "bar"然而,我想在SpringBoot中找到方法,而不是Prometheus。
谢谢。
发布于 2022-11-22 02:39:03
有几种定义标记的方法。
可以在application.yml中定义公共标记
management:
metrics:
tags:
key2: value2如果它不起作用,请确保应用了配置。您可以在本地运行您的服务,并使用http://localhost:<port>/actuator/prometheus检查公开的度量。
作为一种选择,您可以使用MeterRegistryCustomizer
@Configuration
public class MeterRegistryConfiguration {
@Bean
public MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
return (registry) -> registry.config().commonTags("key2", "value2");
}
}如果需要为特定指标定义标记(仅为),则使用MeterFilter
@Bean
public MeterFilter customMeterFilter() {
return new MeterFilter() {
@Override
public Meter.Id map(Meter.Id id) {
if (id.getName().contains("name")) {
return id.withTag(Tag.of("key3", "value3"));
}
return id;
}
};
}https://stackoverflow.com/questions/74525500
复制相似问题