You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SpringBoot中无法获取Spring Data Redis的Actuator指标求助

Redis缓存与连接池JMX监控配置问题解决方案

1. 关联自定义Jedis连接池配置到连接工厂

你定义的JedisClientConfiguration Bean未被关联到实际的Redis连接工厂,导致自定义的JMX配置未生效。需显式创建JedisConnectionFactory并注入自定义配置:

@Bean
public JedisConnectionFactory jedisConnectionFactory(RedisProperties redisProperties, JedisClientConfiguration jedisClientConfiguration) {
    RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(redisProperties.getHost(), redisProperties.getPort());
    if (redisProperties.getPassword() != null) {
        config.setPassword(RedisPassword.of(redisProperties.getPassword()));
    }
    config.setDatabase(redisProperties.getDatabase());
    return new JedisConnectionFactory(config, jedisClientConfiguration);
}

2. 启用Micrometer对Redis指标的收集

虽然你通过RedisCacheManager.builder().enableStatistics()开启了缓存统计,但需确保Micrometer能捕获这些数据:

  • 添加micrometer-registry-jmx依赖(若未添加)
  • 在application.properties中开启Redis指标支持:
    management.metrics.enable.redis=true
    

3. 修正application.properties无效配置

  • 移除无效配置spring.redis.cache.enable-statistics,该属性在Spring Boot 2.6.x中不存在,缓存统计已通过代码开启
  • 保留并确认核心JMX与指标配置:
    spring.jmx.enabled=true
    spring.jmx.unique-names=true
    management.endpoints.jmx.exposure.include=*
    management.endpoints.web.exposure.include=*
    management.metrics.export.jmx.enabled=true
    management.metrics.export.jmx.domain=example-application-domain
    

4. 验证指标是否生成

通过JConsole或VisualVM连接应用,检查以下MBean是否存在:

  • 连接池指标:com.example:type=Pools,name=Redis Connection Pool(对应你设置的JMX命名规则)
  • 缓存统计指标:org.springframework.cache:type=CacheStatistics,name=*(每个缓存名称对应一个实例)

5. 确认Actuator指标展示

Actuator的/actuator/metrics端点中,Redis相关指标名称通常为:

  • 缓存类:cache.gets、cache.misses、cache.puts(带cache.name标签)
  • 连接池类:redis.pool.active、redis.pool.idle、redis.pool.max

若仍无法看到,检查是否存在指标过滤规则,确保未排除Redis相关指标。


内容的提问来源于stack exchange,提问作者Lavish

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 10:02:00