带标签的计数器-如何按尺寸/标签分组?

时间:2018-10-16 20:05:11

标签: java spring-boot metrics micrometer spring-micrometer

我试图通过尺寸/标签功能来了解弹簧微menter的分组。我正在使用StepMeterRegistry并增加计数器,但看不到预期的结果。

创建计数器为

final MeterRegistry myRegistry = new StepMeterRegistry(config, Clock.SYSTEM) {...};

final Counter myCounter1 = myRegistry.counter("myTestCounter", "tag1", "value1");
final Counter myCounter2 = myRegistry.counter("myTestCounter", "tag2", "value2");
final Counter myCounter1n2 = myRegistry.counter("myTestCounter", "tag1", "value1", "tag2", "value2");

递增计数器为

myCounter1.increment();
myCounter2.increment();
myCounter1n2.increment();

我打印时(在步骤持续时间之后)

myCounter1.measure(); => value=1.0
myCounter2.measure(); => value=1.0
myCounter1n2.measure(); => value=1.0

鉴于我所期望的(在步骤持续时间之后),

myCounter1.measure(); => value=2.0
myCounter2.measure(); => value=2.0
myCounter1n2.measure(); => value=1.0

我的理解正确吗?或者我如何实现按功能分组(或按功能选择)?

1 个答案:

答案 0 :(得分:2)

您可以使用Counter通过标签查找MeterRegistry.find(),并自行进行汇总。 AFAICT尚不支持通过标签对汇总值进行开箱即用,我希望汇总会在监视系统中进行。

请参见this test了解其工作原理。