最近我切换到Spring Boot 2了Micrometer. 当我获得这些闪亮的新指标时,我与我们的 DevOps 人员进行了交谈,我们开始将它们导出到Telegraf.
为了区分不同的应用程序和应用程序节点,我们决定使用标签。这对于自定义指标非常有效,但现在我开始考虑预定义。为了对默认指标实现相同的目标,我还需要能够为它们添加额外的标签。
有可能实现这一目标吗?我这样做对吗?
编辑:我尝试了下一种方法:
@Component
public class MyMetricsImpl implements MyMetrics {
@Autowired
protected MyProperties myProperties;
@Autowired
protected MeterRegistry meterRegistry;
@PostConstruct
public void initialize() {
this.meterRegistry.config()
.commonTags(commonTags());
}
@Override
public List<Tag> commonTags() {
List<Tag> tags = new ArrayList<>();
tags.add(Tag.of("application", myProperties.getApplicationName()));
tags.add(Tag.of("node", myProperties.getNodeName()));
return tags;
}
}
Run Code Online (Sandbox Code Playgroud)
问题是我的指标表现正确,甚至一些引导指标(至少http.server.requests)看到我的标签。但是jvm.*,system.*,tomcat.*和其他许多人仍然不具备所需的标签。