Skip to main content
Version: 5.4

Reading Map Metrics

By default, you can read metrics for a given map, such as the primary and backup entry count, last update time, and locked entry count on each member of your cluster. You can access these statistics for the entire map, for the map entries on a specific cluster member, or specific map entries.

Getting Statistics about All Map Entries​

To get statistics for all map entries that are owned by a member, use the getLocalMapStats() method of the Java member API (embedded mode).

The statistics-enabled element of the map is true by default. If you set it to false, the member does not record operation statistics for the map, such as operation counts, latencies, and index statistics. The member also then leaves the map out of the statistics that it reports to the metrics system and Management Center. The getLocalMapStats() method still returns the entry counts and memory costs of the map.

xml
<hazelcast>
...
<map name="myMap">
<statistics-enabled>true</statistics-enabled>
</map>
...
</hazelcast>

Below is example code where getLocalMapStats() and getOwnedEntryCount() get the number of entries owned by this member:

java
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
IMap<String, String> customers = hazelcastInstance.getMap( "customers" );
LocalMapStats mapStatistics = customers.getLocalMapStats();
System.out.println( "number of entries owned on this member = "
+ mapStatistics.getOwnedEntryCount() );
note

The getOwnedEntryMemoryCost() method is also supported for the NATIVE in-memory format.

The following are some of the metrics that you can access via the LocalMapStats object:

  • Number of entries owned by the member (getOwnedEntryCount())
  • Number of backup entries held by the member (getBackupEntryCount())
  • Number of backups per entry (getBackupCount())
  • Memory cost (number of bytes) of owned entries in the member (getOwnedEntryMemoryCost())
  • Creation time of the map on the member (getCreationTime())
  • Number of hits (reads) of the locally owned entries (getHits())
  • Number of get and put operations on the map (getPutOperationCount() and getGetOperationCount())
  • Number of queries executed on the map (getQueryCount() and getIndexedQueryCount()) (it may be imprecise for queries involving partition predicates (PartitionPredicate) on the off-heap storage)

See the LocalMapStats Javadoc to see all the metrics.

note

If you need cluster-wide map statistics, you can get the local map statistics from all members of the cluster and combine them. Alternatively, you can see all map statistics in Hazelcast Management Center.

Getting Statistics about a Specific Map Entry​

To get statistics for a specific map entry, you can use the getEntryView(key) method of one of the following available client libraries. To use this method, the map must have its per-entry-stats-enabled element set to true. The default is false.

This method returns the following statistics:

StatisticDescription
costCost (in bytes) of the entry.
creationTimeCreation time of the entry.
expirationTimeExpiration time of the entry.
hitsNumber of hits of the entry.
keyKey of the entry.
lastAccessTimeLast access time for the entry.
lastStoredTimeLast time the value was saved to a MapStore.
lastUpdateTimeLast time the value was updated.
maxIdleLast set max idle time in milliseconds.
ttlLast set time-to-live in milliseconds.
valueValue of the entry.
versionVersion of the entry.
xml
<hazelcast>
...
<map name="myMap">
<per-entry-stats-enabled>true</per-entry-stats-enabled>
</map>
...
</hazelcast>
java
HazelcastInstance hz = Hazelcast.newHazelcastInstance();

EntryView entry = hz.getMap( "quotes" ).getEntryView( "key" );

System.out.println ( "size in memory : " + entry.getCost() );
System.out.println ( "creationTime : " + entry.getCreationTime() );
System.out.println ( "expirationTime : " + entry.getExpirationTime() );
System.out.println ( "number of hits : " + entry.getHits() );
System.out.println ( "lastAccessedTime: " + entry.getLastAccessTime() );
System.out.println ( "lastUpdateTime : " + entry.getLastUpdateTime() );
System.out.println ( "version : " + entry.getVersion() );
System.out.println ( "key : " + entry.getKey() );
System.out.println ( "value : " + entry.getValue() );