Prometheus 千分尺/普罗米修斯:如何测量加工持续时间?

Prometheus 千分尺/普罗米修斯:如何测量加工持续时间?,prometheus,grafana,micrometer,spring-micrometer,Prometheus,Grafana,Micrometer,Spring Micrometer,我想测量处理某些数据需要多长时间:我的应用程序以固定速率从给定源读取数据。在每个圆圈之前,我存储Instant.now()。我读取数据,将单个时间戳添加到每个条目中。数据被存储、转换,在我通过WebSocket发送数据之前,我想测量now()和初始时间戳之间的持续时间 我试过了 long millis = Duration.between(dataEntry.getReceivedTimestamp(), Instant.now()).toMillis(); LOG.info(millis +

我想测量处理某些数据需要多长时间:我的应用程序以固定速率从给定源读取数据。在每个圆圈之前,我存储
Instant.now()
。我读取数据,将单个时间戳添加到每个条目中。数据被存储、转换,在我通过WebSocket发送数据之前,我想测量
now()
和初始时间戳之间的持续时间

我试过了

long millis = Duration.between(dataEntry.getReceivedTimestamp(), Instant.now()).toMillis();
LOG.info(millis + "ms");
registry.timer("processingDuration").record(millis, TimeUnit.MILLISECONDS);
但将其可视化只允许我使用
processingDuration\u seconds\u count
\u max
\u sum
count
sum
随着时间的推移而增加(当然),
max
在大多数时间是恒定的。那么,我如何看待更高和更低的负载高原呢?我尝试了
irate(processingDuration\u seconds\u sum[10m])
至少查看跳跃,但由于
irate()
仅使用两个数据点,我仍然无法轻松识别较长的高负载周期。另外:图中的值约为0.6,而记录的ms约为5-10,因此我在这里丢失了实际值

因此,我尝试使用
仪表
,它应该允许增加和减少值:

registry.gauge("processingDurationGauge", millis);
我原以为这会在记录的毫秒范围内上下波动,但它始终是92


如何测量数据的整个时间?

问题是,
long
不是线程安全的,请参阅。按预期操作:

private final AtomicLong processingDuration;

// ...

// in constructor:
processingDuration = meterRegistry.gauge("processingDuration", new AtomicLong(0L));

// ...

// before finishing the data entries' handling:
long millis = Duration.between(dataEntry.getReceivedTimestamp(), Instant.now()).toMillis();
LOG.info(millis + "ms");
processingDuration.set(millis);

使用计时器和
记录
是正确的解决方案

long millis = Duration.between(dataEntry.getReceivedTimestamp(), Instant.now()).toMillis();
LOG.info(millis + "ms");
registry.timer("processingDuration").record(millis, TimeUnit.MILLISECONDS);
假设您每30秒刮一次,您可以使用
\u sum
\u count
来获得平均记录的持续时间:

increase(processingDuration_seconds_sum[1m])/increase(processingDuration_seconds_count[1m])
如果您想将当前持续时间的表现与过去一天的平均值进行比较:

((increase(processingDuration_seconds_sum[1m])/
increase(processingDuration_seconds_count[1m]))*1.50) >
increase(processingDuration_seconds_sum[24h])/
increase(processingDuration_seconds_count[24h])

这只会返回1m平均值大于日平均值1.5倍的值。(我还没有测试过这个查询,但它应该知道这个想法)。

与仪表相比,它有什么优势?我看到了一个缺点:生成的图形与记录的毫秒UST saw不匹配,后者看起来很相似(它们使用
rate()
)。不管怎样:这给我指明了正确的方向,我马上就接受。谢谢,阿加尼,我很困惑——普罗米修斯将其导出为秒,即使我将其添加到计时器毫秒中。那么普罗米修斯能把它转换成秒吗?或者它显示实际记录的毫秒,但标记为秒?