此内容没有您所选择的语言版本。
Chapter 6. Configuring Statistics, Metrics, and JMX
Enable statistics that Data Grid exports to a metrics endpoint or via JMX MBeans. You can also register JMX MBeans to perform management operations.
6.1. Enabling Data Grid Statistics
Data Grid lets you enable statistics for Cache Managers and specific cache instances.
Data Grid servers provide default infinispan.xml
configuration files that enable statistics for Cache Managers. If you use the default Data Grid server configuration, you only need to enable statistics when you configure caches.
Procedure
- Enable statistics declaratively or programmatically.
Declaratively
<cache-container statistics="true"> 1 <local-cache name="mycache" statistics="true"/> 2 </cache-container>
Programmatically
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder() .cacheContainer().statistics(true) 1 .build(); ... Configuration config = new ConfigurationBuilder() .statistics().enable() 2 .build();
Enabling statistics for Cache Managers does not globally enable statistics for caches. This configuration only collects statistics for the Cache Manager.
6.2. Enabling Data Grid Metrics
Data Grid is compatible with the Eclipse MicroProfile Metrics API and can generate gauge and histogram metrics.
-
Data Grid metrics are provided at the
vendor
scope. Metrics related to the JVM are provided in thebase
scope for Data Grid server. - Gauges provide values such as the average number of nanoseconds for write operations or JVM uptime. Gauges are enabled by default. If you enable statistics, Data Grid automatically generates gauges.
- Histograms provide details about operation execution times such as read, write, and remove times. Data Grid does not enable histograms by default because they require additional computation.
Procedure
- Configure metrics declaratively or programmatically.
Declaratively
<cache-container statistics="true"> 1 <metrics gauges="true" histograms="true" /> 2 </cache-container>
Programmatically
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder() .statistics().enable() 1 .metrics().gauges(true).histograms(true) 2 .build();
6.3. Enabling and Configuring JMX
You can enable JMX with Data Grid servers to collect statistics and perform administrative operations.
You can enable JMX without enabling statistics if you want to use management operations only. In this case, Data Grid provides 0
values for all statistics.
Procedure
- Enable JMX declaratively or programmatically.
Declaratively
<cache-container>
<jmx enabled="true" /> 1
</cache-container>
Programmatically
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder()
.jmx().enable() 1
.build();
Reference
6.3.1. Naming Multiple Cache Managers
In cases where multiple Data Grid Cache Managers run on the same JVM, you should uniquely identify each Cache Manager to prevent conflicts.
Procedure
- Uniquely identify each cache manager in your environment.
For example, the following examples specify "Hibernate2LC" as the cache manager name, which results in a JMX MBean named org.infinispan:type=CacheManager,name="Hibernate2LC"
.
Declaratively
<cache-container name="Hibernate2LC"> <jmx enabled="true" /> ... </cache-container>
Programmatically
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder() .cacheManagerName("Hibernate2LC") .jmx().enable() .build();
6.3.2. Registering MBeans In Custom MBean Servers
Data Grid includes an MBeanServerLookup
interface that you can use to register MBeans in custom MBeanServer instances.
Procedure
-
Create an implementation of
MBeanServerLookup
so that thegetMBeanServer()
method returns the custom MBeanServer instance. - Configure Data Grid with the fully qualified name of your class, as in the following example:
Declaratively
<cache-container> <jmx enabled="true" mbean-server-lookup="com.acme.MyMBeanServerLookup" /> </cache-container>
Programmatically
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder() .jmx().enable().mBeanServerLookup(new com.acme.MyMBeanServerLookup()) .build();
6.3.3. Data Grid MBeans
Data Grid exposes JMX MBeans that represent manageable resources.
org.infinispan:type=Cache
- Attributes and operations available for cache instances.
org.infinispan:type=CacheManager
- Attributes and operations available for cache managers, including Data Grid cache and cluster health statistics.
For a complete list of available JMX MBeans along with descriptions and available operations and attributes, see the Data Grid JMX Components documentation.
Reference