英文:
Supporting multiple metrics via prometheus (statsd and prometheus)
问题
我正在将指标收集系统从statsd迁移到Prometheus。这是一个Spring Boot应用程序,基于Micrometer。我想知道是否有一种方法可以同时开始支持分层的statsd指标和维度化的Prometheus指标。
目前,我创建计时器的方式是
Metrics.timer("apiName.endpointName.latency").record(latency);
这对于statsd来说是可以的,但对于Prometheus则不起作用。我需要支持带有标签的单独指标,例如
service_latency {api="apiName", endpoint="endpointName"}
是否有可能同时支持这两种方式?
英文:
I am in the middle of moving the metrics collection system from statsd to Prometheus. It is a spring boot app and based on a micrometer. I am wondering if there is a way to start supporting both hierarchical statsd metrics and also dimensional Prometheus metrics at the same time.
Currently, the way I create a timer is
Metrics.timer("apiName.endpointName.latency").record(latency)
This is fine for statsd but does not work for Prometheus. I need to support a separate metric with tags such as
service_latency {api="apiName", endpoint="endpointName"}
Is it possible to support both at the same time?
答案1
得分: 1
你可以同时支持这两种方式。推荐的方法是:
Metrics.timer("latency", Tags.of("api", apiName, "endpoint", endpointName)).record(latency)
然后使用'分层的命名约定'
这样,statsd 的标签会按照你需要的层次结构放置,而 Prometheus 的指标已经被标记,可以直接使用。
另一种方法(不推荐)
另一种方法(不太理想的方法)是在两个仪表的存储库之间复制该仪表。
当前,当你使用 Metrics.timer("myMeter")
时,你正在使用全局的复合仪表注册表,它将仪表委托给底层注册表。
相反,如果你分别调用每个注册表:
statsdRegistry.timer("myMeter")...
prometheusRegistry.timer("myMeter")...
不幸的是,这将需要你进行更多手动更改,并在注册表之间复制代码。但是,这确实是一个选项。
英文:
You can support both at the same time. The recommended way is
Metrics.timer("latency", Tags.of("api", apiName, "endpoint", endpointName.)).record(latency)
Then use a 'hierarchical naming convention'
That way the statsd tags are placed in the hierarchy as you need them, and the Prometheus metrics are already tagged and ready to be used.
Alternative (not recommended)
An alternative (and less appealing approach) would be to duplicate the meter between the 2 meter repositories.
Currently when you use Metrics.timer("myMeter")
you are using the global composite meter registry, which delegates the meters to the underlying registries.
Instead if you call each registry individually:
statsdRegistry.timer("myMeter")...
prometheusRegistry.timer("myMeter")...
Unfortunately that will require more manual changes on your part and a duplication of code between the registries. But, you DO have that as an option.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论