【问题标题】:How to expose Prometheus metrics with RedisCacheManager?如何使用 RedisCacheManager 公开 Prometheus 指标?
【发布时间】:2020-10-02 04:43:15
【问题描述】:

我有一个 Spring Boot 2 应用程序,它已经实现了带有 Caffeine 缓存管理器的缓存。缓存是通过@Cacheable@CacheEvict@CachePut 注释以标准方式实现的。

我迁移了应用程序以使用 Redis 在 pod 之间分配缓存。

现在的问题在于指标。在迁移之前Caffeine 暴露了缓存指标,如cache_puts_totalcache_gets_total 等,现在什么都没有了。 RedisCacheManager 中的指标是否实现了某些功能?我什么也找不到。

【问题讨论】:

    标签: spring-boot metrics redis-cache


    【解决方案1】:

    不幸的是,您可以在 Spring Boot 文档中看到:52. Metrics,默认情况下 Spring Boot 不提供 Redis 的缓存统计信息:

    默认情况下,Spring Boot 提供 EhCache、Hazelcast、Infinispan、JCache 和 Guava 的缓存统计信息。如果您最喜欢的缓存库不支持开箱即用,您可以添加额外的 CacheStatisticsProvider bean。

    您可以使用Redisson 作为自己实现此功能的另一种选择。这个 Redis 客户端带有一个 integration with Spring,它公开了 Prometheus 指标。您的指标看起来就像您暗示的那样:

    # HELP cache_gets_total the number of times cache lookup methods have returned an uncached (newly loaded) value, or null
    # TYPE cache_gets_total counter
    cache_gets_total{cache="...",cacheManager="...",name="...",result="miss",} 0.0
    cache_gets_total{cache="...",cacheManager="...",name="...",result="hit",} 0.0
    
    # HELP cache_puts_total The number of entries added to the cache
    # TYPE cache_puts_total counter
    cache_puts_total{cache="...",cacheManager="...",name="...",} 0.0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-20
      • 1970-01-01
      • 2022-08-11
      • 2019-12-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多