3.5. 公开数据网格统计


Data Grid 支持 Spring Boot Actuator 将缓存统计信息作为指标公开。

流程

  1. 在您的 pom.xml 文件中添加以下内容:

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
      <version>${version.spring.boot}</version>
     </dependency>
    
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      <version>${version.spring.boot}</version>
    </dependency>
    Copy to Clipboard Toggle word wrap
  2. 以编程方式或声明性方式激活相应缓存实例的统计信息。

    以编程方式

    @Bean
    public InfinispanCacheConfigurer cacheConfigurer() {
      return cacheManager -> {
         final org.infinispan.configuration.cache.Configuration config =
               new ConfigurationBuilder()
                     .jmxStatistics().enable()
                     .build();
    
         cacheManager.defineConfiguration("my-cache", config);
      };
    }
    Copy to Clipboard Toggle word wrap

    声明性

    <local-cache statistics="true"/>
    Copy to Clipboard Toggle word wrap

Spring Boot Actuator registry 在应用程序启动时绑定缓存实例。

如果您动态创建缓存,您应该使用 CacheMetricsRegistrar bean 将缓存绑定到 Actuator registry,如下所示:

@Autowire
CacheMetricsRegistrar cacheMetricsRegistrar;

@Autowire
CacheManager cacheManager;
...

cacheMetricsRegistrar.bindCacheToRegistry(cacheManager.getCache("my-cache"));
Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat