Cache Metrics

❗️

This is a legacy Apache Ignite documentation

The new documentation is hosted here: https://ignite.apache.org/docs/latest/

Apache Ignite allows to keep an eye on the distributed cache specific statistics available via the CacheMetrics interface.

The CacheMetrics interface has a variety of metrics, such as - the total number of put and get operations processed by a cache, average put or get time, total number of evictions, current write-behind cache store buffer size, and more.

Enabling Cache Metrics

To enable cache metrics, set CacheConfiguration.setStatisticsEnabled(boolean) to true for every cache you want to collect the metrics for. The example below shows how to do this for a cache named test-cache:

<bean class="org.apache.ignite.configuration.IgniteConfiguration">
  <property name="cacheConfiguration">
    <list>
      <bean class="org.apache.ignite.configuration.CacheConfiguration">
        <property name="name" value="test-cache"/>
      
        <!-- Enable statistics for the cache. -->
        <property name="statisticsEnabled" value="true"/>
      </bean>
    </list>
  </property>
</bean>
IgniteConfiguration cfg = new IgniteConfiguration();

CacheConfiguration cacheCfg = new CacheConfiguration("test-cache");
        
// Enable statistics for the cache.
cacheCfg.setStatisticsEnabled(true);

// Start the node.
Ignition.start(cfg);

Getting Cache Metrics

There are several ways to get the latest metrics snapshot of a specific cache:

  • IgniteCache.metrics() - gets the metrics snapshot of the whole cluster where the cache is deployed.
  • IgniteCache.metrics(ClusterGroup grp) - gets the metrics snapshot for Apache Ignite nodes that belong to the given cluster group.
  • IgniteCache.localMetrics() - gets the local node's metrics snapshot for the cache.
IgniteCache<Integer, Person> cache = ignite.getOrCreateCache("myCache");

// Get cache metrics 
CacheMetrics cm = cache.metrics();

System.out.println("Avg put time: " + cm.getAveragePutTime());

System.out.println("Avg get time: " + cm.getAverageGetTime());

For a complete list of metrics available, refer to CacheMetrics javadoc.

Using JMX Bean

You can also get access to cache metrics via the CacheMetricsMXBean interface. You can connect to the bean from any JMX-compliant tool or API. If you need to work with the bean from your application, use IgniteCache.mxBean() or IgniteCache.localMxBean() to get a bean reference.

Use the CacheMetricsMXBean.enableStatistics() method exposed by a special JMX bean to activate collecting cache metrics.

For a complete list of metrics available, refer to CacheMetricsMXBean javadoc.

Cache Size Calculation

To learn how to calculate cache size, see Memory Usage Calculation.