我正在尝试使用prometheus来监视spring中的一些缓存指标。缓存是用@Cacheable创建的,我的配置如下:
management.endpoints:
web.exposure.include: "*"
metrics.enabled: true
prometheus.enabled: true
management.metrics:
export.prometheus.enabled: true
cache.instrument: true我的缓存是用一个简单的@Cacheable('mycache')创建的--我没有其他缓存代码或设置。--我也不使用任何特定的缓存,只提供内置的一个.
我确实在/actuator/caches/列表中看到了我的缓存,但在/metrics或/prometheus端点中都没有详细说明。
我的期望是,一些缓存度量将同时发布到/actuator/metrics和/actuator/prometheus端点。
我看到了一些关于需要手动注册缓存的注释,但我也无法做到这一点(我也不确定它真的存在)。当尝试这样做时,问题是我不能在CacheMetricsRegistrar bean中自动运行。还没找到。
发布于 2019-10-21 20:42:46
对于内置的基于hashmap的缓存,没有千分尺绑定。请参阅https://github.com/micrometer-metrics/micrometer/tree/master/micrometer-core/src/main/java/io/micrometer/core/instrument/binder/cache,以了解从框中创建的实现。
这些实现跟踪它们的命中/失误本身。由于没有任何东西跟踪hashmap没有跟踪度量,所以没有可用的表。
发布于 2019-10-20 16:39:02
您似乎弄错了您的属性,应该是端点和额外的s。
您的属性应该是management.endpoint.prometheus.enabled
您可以在这里引用所有执行机构的属性。
编辑:提到的终结点属性如Spring 2.2所示
编辑2
当阅读更多关于执行器缓存的内容时,请参阅#6.3.5中的这个URL。Cache Metrics我发现
只有启动时可用的缓存才绑定到注册表。对于在启动阶段后动态创建或以编程方式创建的缓存,需要显式注册.为了使这个过程更容易,可以使用CacheMetricsRegistrar bean。
我进一步研究了CacheMetricsRegistrar,在这个URL中,我找到了一个示例,我在我的执行器示例项目中实现了这个示例。
现在,我可以在应用程序的Prometheus中看到书籍缓存详细信息,如下所示
# TYPE cache_gets_total counter
cache_gets_total{cache="books",cacheManager="cacheManager",name="books",result="hit",} 4.0
cache_gets_total{cache="books",cacheManager="cacheManager",name="books",result="miss",} 2.0发布于 2021-02-24 12:57:34
正如checketts所说的那样,没有以千分尺为ConcurrentHashMap支持的简单实现注册的指标。
支持Spring中的指标的缓存库也在这里列出:https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-metrics-cache。
它还说
只有在启动时配置的缓存才绑定到注册表。
这意味着必须声明为启动时要监视的缓存,如下所示:
spring.cache.cache-names=books您将在application.properties中找到该属性,请参阅:https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html#common-application-properties-cache。
如果要进行测试,请添加例如咖啡因:
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>然后,如果prometheus端点被激活,您将看到以下示例:
# TYPE cache_size gauge
cache_size{cache="books",cacheManager="cacheManager",name="books",} 2.0用Spring 2.4测试代码
https://stackoverflow.com/questions/58475039
复制相似问题