问题描述
我最近将Spring Boot应用程序从1.5升级到了2.0.1.我还使用千分尺将Prometheus集成迁移到了新的执行器方法.现在大多数事情都可以正常工作-包括一些自定义计数器和量规.
I recently upgraded a spring boot application from 1.5 to 2.0.1. I also migrated the prometheus integration to the new actuator approach using micrometer. Most things work now - including some custom counters and gauges.
我注意到新的普罗米修斯端点/actuator/prometheus
不再发布spring缓存指标(大小和命中率).
I noted the new prometheus endpoint /actuator/prometheus
does no longer publish the spring cache metrics (size and hit ratio).
The only thing I could find was this issue and its related commit.
仍然无法在Prometheus导出中获取缓存指标.我尝试设置一些属性:
Still I can't get cache metrics on the prometheus export. I tried settings some properties:
management.metrics.cache.instrument-cache=true
spring.cache.cache-names=cache1Name,cache2Name...
但是没有任何真正的效果.我可以看到Hazelcast缓存管理器正在启动,注册了缓存管理器bean等等-但是/metrics
和/prometheus
均未显示任何统计信息.使用@Cacheable
批注填充缓存.这与Spring Boot 1.5配合使用-我认为是通过Hazelcast通过JMX公开了其指标,而prometheus出口商则从那里进行了采集?
But nothing really works. I can see the Hazelcast cache manager starting up, registering the cache manager bean and so on - but neither /metrics
nor /prometheus
show any statistics. The caches are populated using the @Cacheable
annotation. This worked with Spring Boot 1.5 - I think via Hazelcast exposing its metrics via JMX and the prometheus exporter picking it up from there?
现在不确定如何将其连接在一起.欢迎任何提示!
Not sure now how to wire this together. Any hints are welcome!
推荐答案
您回答了我的问题后,我可以为此提供答案.
As you've answered my question, I can provide an answer for this.
然后文档的这一部分适用于您:
Then this section of the doc applies to you:
因此,您必须自己注册此类缓存,希望它非常简单,类似于:
So you have to register such caches yourself, hopefully it is pretty easy, something like:
public class MyComponent {
private final CacheMetricsRegistrar cacheMetricsRegistrar;
private final CacheManager cacheManager
public MyComponent(CacheMetricsRegistrar cacheMetricsRegistrar,
CacheManager cacheManager) { ... }
public void register() {
// you have just registered cache "xyz"
Cache xyz = this.cacheManager.getCache("xyz");
this.cacheMetricsRegistrar.bindCacheToRegistry(xyz);
}
}
您可以将此代码包含在现有代码中.如果您不想这样做,那么您需要在现有代码之后运行其他操作,以将这些缓存注册到注册表中.
you can include this code in your existing code. If you don't want to do that, then you need something else that runs after your existing code to register those caches to the registry.
这篇关于升级到Spring Boot 2之后,如何将缓存指标公开给Prometheus?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!