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
- YAML
<hazelcast>
...
<map name="myMap">
<statistics-enabled>true</statistics-enabled>
</map>
...
</hazelcast>
hazelcast:
map:
myMap:
statistics-enabled: true
Below is example code where getLocalMapStats() and getOwnedEntryCount() get the number of entries owned by this member:
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() );
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()andgetGetOperationCount()) - Number of queries executed on the map (
getQueryCount()andgetIndexedQueryCount()) (it may be imprecise for queries involving partition predicates (PartitionPredicate) on the off-heap storage)
See the LocalMapStats Javadoc to see all the metrics.
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:
| Statistic | Description |
|---|---|
cost | Cost (in bytes) of the entry. |
creation | Creation time of the entry. |
expiration | Expiration time of the entry. |
hits | Number of hits of the entry. |
key | Key of the entry. |
last | Last access time for the entry. |
last | Last time the value was saved to a MapStore. |
last | Last time the value was updated. |
max | Last set max idle time in milliseconds. |
ttl | Last set time-to-live in milliseconds. |
value | Value of the entry. |
version | Version of the entry. |
- XML
- YAML
<hazelcast>
...
<map name="myMap">
<per-entry-stats-enabled>true</per-entry-stats-enabled>
</map>
...
</hazelcast>
hazelcast:
map:
myMap:
per-entry-stats-enabled: true
- Java (Embedded Mode)
- Java (Client/Server Mode)
- C++
- C Sharp
- Node.js
- Python
- Go
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() );
HazelcastInstance hz = HazelcastClient.newHazelcastClient();
EntryView entry = hz.getMap( "map" ).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() );
auto hz = hazelcast::new_client().get();
auto map = hz.get_map( "map" ).get();
auto entry = map->get_entry_view<std::string, std::string>("key").get();
std::cout << "size in memory : " << entry->cost << std::endl;
std::cout << "creationTime : " << entry->creation_time << std::endl;
std::cout << "expirationTime : " << entry->expiration_time << std::endl;
std::cout << "number of hits : " << entry->hits << std::endl;
std::cout << "lastAccessedTime: " << entry->last_access_time << std::endl;
std::cout << "lastUpdateTime : " << entry->last_update_time << std::endl;
std::cout << "version : " << entry->version << std::endl;
std::cout << "key : " << entry->key << std::endl;
std::cout << "value : " << entry->value << std::endl;
await using var client = await HazelcastClientFactory.StartNewClientAsync();
await using var map = await client.GetMapAsync<string, string>("map");
var entry = await map.GetEntryViewAsync("key");
Console.WriteLine($"Size in memory : {entry.Cost}");
Console.WriteLine($"Creation time : {entry.CreationTime}");
Console.WriteLine($"Expiration time : {entry.ExpirationTime}");
Console.WriteLine($"Number of hits : {entry.Hits}");
Console.WriteLine($"Last access time: {entry.LastAccessTime}");
Console.WriteLine($"Last update time: {entry.LastUpdateTime}");
Console.WriteLine($"Last update time: {entry.LastUpdateTime}");
Console.WriteLine($"Version : {entry.Version}");
Console.WriteLine($"Key : {entry.Key}");
Console.WriteLine($"Value : {entry.Value}");
const client = await Client.newHazelcastClient();
const map = await client.getMap('map');
const entryView = await map.getEntryView('key');
console.log(`size in memory : ${entry.cost}`);
console.log(`creationTime : ${entry.creationTime}`);
console.log(`expirationTime : ${entry.expirationTime}`);
console.log(`number of hits : ${entry.hits}`);
console.log(`lastAccessedTime: ${entry.lastAccessTime}`);
console.log(`lastUpdateTime : ${entry.lastUpdateTime}`);
console.log(`version : ${entry.version}`);
console.log(`key : ${entry.key}`);
console.log(`value : ${entry.value}`);
client = hazelcast.HazelcastClient()
entry = client.get_map("map").get_entry_view("key").result()
print("size in memory :", entry.cost)
print("creationTime :", entry.creation_time)
print("expirationTime :", entry.expiration_time)
print("number of hits :", entry.hits)
print("lastAccessedTime:", entry.last_access_time)
print("lastUpdateTime :", entry.last_update_time)
print("version :", entry.version)
print("key :", entry.key)
print("value :", entry.value)
// error handling is omitted for brevity
hzclient, _ := hazelcast.StartNewClient()
ctx := context.TODO()
myMap, _ := hz.GetMap(ctx, "my-map")
entry, _ := myMap.GetEntryView(ctx, "key")
fmt.Println("Size in memory :", entry.Cost)
fmt.Println("Creation time :", entry.CreationTime)
fmt.Println("Expiration time :", entry.ExpirationTime)
fmt.Println("Number of hits :", entry.Hits)
fmt.Println("Last accessed time :", entry.LastAccessTime)
fmt.Println("Last updated time :", entry.LastUpdateTime)
fmt.Println("Version :", entry.Version)
fmt.Println("Key :", entry.Key)
fmt.Println("Value :", entry.Value)