使用 Micrometer 计时器跨 Java 进程?

huangapple go评论71阅读模式
英文:

Using Micrometer Timer across Java processes?

问题

我想使用 Micrometer 收集在一个 Java 进程中启动并在另一个 Java 进程中完成的任务的持续时间指标(它们通过 Kafka 进行通信)。

我考虑使用 LongTaskTimer.start() 方法,它会返回一个 LongTaskTimer.Sample 对象,然后将其与 Kafka 消息一起传递给第二个进程,然后使用 LongTaskTimer.Sample.stop() 方法记录任务持续时间。但是不清楚 LongTaskTimer.Sample 对象是否可以被序列化,以及总体上这种方法是否可行。

上述方法有可能实现吗?如何实现?如果不行,实现所述目标最简单的方法是什么?

不确定是否重要 - 我的运行环境是 Spring Boot 2,我正在将指标收集到 Prometheus(使用标准的 Micrometer Prometheus 注册表)。

英文:

I would like to use Micrometer to collect duration metrics for a task that starts in one Java process and finishes in another Java process (communicating via Kafka between them).

I was thinking to use LongTaskTimer.start() that returns a LongTaskTimer.Sample object, then pass it to the second process along with the Kafka message, and then use LongTaskTimer.Sample.stop() to record the task duration. But it is not clear whether LongTaskTimer.Sample objects can be serialized, and also in general whether such approach could work.

Is it possible to make the above approach work? How? If not, what is the easiest way to achieve the stated goal?

Not sure if it matters - my runtime environment is Spring Boot 2, and I am collecting the metrics to Prometheus (using standard micrometer prometheus registry).

答案1

得分: 3

Micrometer不支持跨多个JVM生成的指标。
你的选择有:

  1. 使用多个指标,然后在Grafana中创建一个视图,该视图将具有一个查询,该查询将两个(或多个)指标相加。这可能不会精确测量流量,而更像是一种平均值,可以提供对系统中发生情况的“感觉”。

  2. 使用某种类型的追踪软件。诸如Jaeger之类的工具(请参阅此处示例)

  3. 自己实现流程(例如,测量处理A中一个操作的时间差,然后将此值放入kafka消息,然后在处理B中读取此值,并在完成后添加自己的延迟等)。链中的最后一个进程可以记录该值或其他内容(或者如果需要,使用Micrometer)。

英文:

Micrometer doesn't support metrics that spawn across multiple JVMs.
Your options are:

  1. Use multiple metrics and then create a view in grafana that will have a query that sums two (or more) metrics. It won't probably be an exact measurement of the flow, but rather some kind of average value that can provide a "feeling" of what happens in the system.

  2. Use some kind of tracing software. Stuff like Jaeger (see here an example)

  3. Implement the flow yourself (like measuring the time diff of one operation in process A, then putting this value in kafka message, then reading this value in process B and adding up its own latency when its done and so on. The last process in chain can log the value or something (or use the Micrometer if you want)

huangapple
  • 本文由 发表于 2020年5月3日 15:50:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/61571212.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定