1

Lets say my spring microservice processes data. Every time a successful processing event occurs, for metrics, I update the micrometer counter. This is registered to a Graphite Registry.

registry = new GraphiteMeterRegistry(new GraphiteConfiguration(), Clock.SYSTEM, HierarchicalNameMapper.DEFAULT);
Counter counter = Counter.builder("process").tag("status","success").register(registry);

So far, it sounds good. But what if I have to create and deploy multiple instances of my service?

How do I get the aggregated count of all successful events from all the instances?

To illustrate my case further, I log the counter.count() value on each increment. Here is what i see ->

<Instance 1> <time> <package-name> Count :122
<Instance 2> <time> <package-name> Count :53

So when I run the graphite query on graphana -

process.status.success.count

I tend to get the random count from either of these instances.

What I need is a query like -

process.service-instance.status.success.count 

so that I can run a summarize() function in the end.

Update Now I'm able to source data from all instances by getting the service instance ID. But that presents a new problem - Since I restart my services time and again, and my service-id changes every time, how do I source data from ONLY ACTIVE services?

Since process.*.status.success.count represents aggregate count of ALL services - dead or alive

4

1 回答 1

0

切勿使用实例 ID 进行聚合。当实例重新启动时,实例 ID 将发生变化。(仅将 instance-id 用于记录/调试/记录保存目的。)

使用 service-id 进行聚合。

对于千分尺,您可以在常用标签中添加服务名称。

registry.config().commonTags("service", "xyz-service");

通用标签在注册表级别定义,与该注册表关联的每个指标都将添加通用标签。

并且,对于死或活的情况:当实例处于活动状态时推送指标。因此,如果您想知道某个步骤运行了多少次,则需要考虑该计数。

要从活动实例中获取数据,请使用时间过滤器。这将返回由在该持续时间内活动的实例推送的数据(为什么?因为死实例不推送指标)。

于 2019-01-05T17:45:39.513 回答