我在 Spring Boot 应用程序中使用 Caffeine 缓存。所有指标都已启用,因此我将它们放在 Prometheus 和 Grafana 上。
基于cache_gets_total
指标,我想构建一个HitRate 图表。
我试图获得缓存命中:
delta(cache_gets_total{result="hit",name="myCache"}[1m])
并且都从缓存中获取:
sum(delta(cache_gets_total{name="myCache"}[1m]))
这两个指标都正常工作并且具有值。但是当我试图获得命中率时,我没有数据点。我试过的查询:
delta(cache_gets_total{result="hit",name="myCache"}[1m]) / sum(delta(cache_gets_total{name="myCache"}[1m]))
为什么这个查询不起作用以及如何根据我从 Spring Boot 和 Caffeine 获得的信息获取命中率图表?
最佳答案
在 prometheus 中分别运行(“缓存命中”和“全部获取”)查询,并将您获得的标签集与结果进行比较。 要使“/”操作起作用,双方必须完全具有相同的标签(和值)。通常需要一些聚合来“删除”不需要的维度/标签(例如:如果您已经从两个查询中获得一个值,那么只需将它们都包装在 sum() 中 - 在划分之前)。
关于spring-boot - 使用 prometheus 查询缓存命中率图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57161234/