Configure and Use Statistics

In this procedure it is assumed that you understand Basic Configuration and Programming.
  1. Configure the gemfire.properties for the statistics monitoring and archival that you need:
    1. Enable statistics gathering for the distributed system. This is required for all other statistics activities:
      statistic-sampling-enabled=true
    2. Change the statistics sample rate as needed. Example:
      statistic-sampling-enabled=true
      statistic-sample-rate=2000
    3. To archive the statistics to disk, enable that and set any file or disk space limits that you need. Example:
      statistic-sampling-enabled=true
      statistic-archive-file=myStatisticsArchiveFile
      archive-file-size-limit=100
      archive-disk-space-limit=1000
    4. If you need time-based statistics, enable that. Time-based statistics require statistics sampling and archival. Example:
      statistic-sampling-enabled=true
      statistic-archive-file=myStatisticsArchiveFile
      enable-time-statistics=true
  2. Enable transient region and entry statistics gathering on the regions where you need it. Expiration requires statistics. Example:
    <region name="myRegion" refid="REPLICATE">
    	<region-attributes statistics-enabled="true">
    	</region-attributes>
    </region>
    Note: Region and entry statistics are not archived and can only be accessed through the API. As needed, retrieve region and entry statistics through the getStatistics methods of the Region and Region.Entry objects. Example:
    out.println("Current Region:\n\t" + this.currRegion.getName());
    RegionAttributes attrs = this.currRegion.getAttributes();
    if (attrs.getStatisticsEnabled()) {
    	CacheStatistics stats = this.currRegion.getStatistics();
    	out.println("Stats:\n\tHitCount is " + stats.getHitCount() +
    		"\n\tMissCount is " + stats.getMissCount() +
    		"\n\tLastAccessedTime is " + stats.getLastAccessedTime() +
    		"\n\tLastModifiedTime is " + stats.getLastModifiedTime());
    }
  3. Create and manage any custom statistics that you need through the cache.xml and the API. Example:
    // Create custom statistics
    <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE statistics PUBLIC
        "-//GemStone Systems, Inc.//GemFire Statistics Type//EN"
        "http://www.gemstone.com/dtd/statisticsType.dtd">
      <statistics>
        <type name="StatSampler">
          <description>Stats on the statistic sampler.</description>
          <stat name="sampleCount" storage="int" counter="true">
            <description>Total number of samples taken by this sampler.</description>
            <unit>samples</unit>
          </stat>
          <stat name="sampleTime" storage="long" counter="true">
            <description>Total amount of time spent taking samples.</description>
            <unit>milliseconds</unit>
          </stat>
        </type>
      </statistics>
    // Update custom stats through the API
    this.samplerStats.incInt(this.sampleCountId, 1);
    this.samplerStats.incLong(this.sampleTimeId, nanosSpentWorking / 1000000);
  4. Access archived statistics through these utilities: