Memory region monitoring

The DataRegionMetrics interface is the gateway to Apache Ignite's memory region monitoring APIs. The first step to collect metrics is to enable it. The DataStorageMetrics interface provides methods to get metrics for data storage. The following Java code snippet enables metrics for a data region:

DataRegionConfiguration region1 = new DataRegionConfiguration();
region1.setName("region1");
region1.setMetricsEnabled(true);

It can also be enabled and disabled at runtime via JMX beans.

ignite.dataRegionMetrics() returns a collection of DataRegionMetrics. You can invokes methods on DataRegionMetrics to get different statistics.

ignite.dataStorageMetrics() returns a DataStorageMetrics instance to check the data storage metrics.

The following are the steps to create two data regions, create a data storage configuration, and collect metrics for them:

  1. Create a Java class called MemoryMonitoring:
      public class MemoryMonitoring{
private static final int KB = 1024;
private static final int MB = 1024 * 1024;
private static final long GB = MB * 1024;

public static void main(String[] args) {
  1.  Add a data region, region1, enable metrics, and set the initial and maximum size:
     DataRegionConfiguration region1 = new DataRegionConfiguration();
region1.setName("region1");
region1.setMetricsEnabled(true);
region1.setPersistenceEnabled(true);
region1.setInitialSize(500 * MB);
region1.setMaxSize(500 * MB);
  1. Create another region, region2, enable metrics, but don't set the initial and maximum size:
     DataRegionConfiguration region2 = new DataRegionConfiguration();
region2.setName("region2");
region2.setPersistenceEnabled(true);
region2.setMetricsEnabled(true);
  1. Create a data storage configuration and set the data region configurations and page size, and enable data storage metrics:
       DataStorageConfiguration storageCfg = new 
DataStorageConfiguration();
storageCfg.getDefaultDataRegionConfiguration().setMaxSize(6L * GB);
storageCfg.setMetricsEnabled(true);
storageCfg.setPageSize(2 * KB);
storageCfg.setDataRegionConfigurations(region1, region2);
  1. Create an Ignite configuration, set the data storage configuration, and start an Ignite server instance with the configuration:
      IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setPeerClassLoadingEnabled(true);
cfg.setDataStorageConfiguration(storageCfg);
Ignite ignite = Ignition.start(cfg);
  1. Retrieve the data region metrics collection and loop through it:
       System.out.println("Data Region Metrics...");
Collection<DataRegionMetrics> dataRegionMetrics =
ignite.dataRegionMetrics();
dataRegionMetrics.forEach(m -> {
System.out.println(">>>*********************************<<<<");
System.out.println(">>> Memory Region Name: " + m.getName());
System.out.println(">>> OffHeapSize Size: " +
m.getOffHeapSize());
System.out.println(">>> Physical Memory Size: " +
m.getPhysicalMemorySize());
System.out.println(">>>*********************************<<<<");
});
  1. Get the data storage metrics and print the results:
     System.out.println("Data Storage Metrics...");
DataStorageMetrics dataStorageMetrics = ignite.dataStorageMetrics();
System.out.println("_____________________________");
System.out.println("Off-heap size = "+
dataStorageMetrics.getOffHeapSize());
System.out.println("Allocated size= "+
dataStorageMetrics.getTotalAllocatedSize());
}
}
  1. Run the program. It will print the metrics for data regions and data storage. 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.104.27