javacachingignitemetricsapacheignite

Trouble getting metrics on Apache Ignite


I have a cluster of 2 servers and 2 thick clients. Each thick client has 2 caches in replicated mode. I have to create an API which displays the metrics of the server (Heap allocated, heap used, persistence allocated and used etc...) The API is another thick client connected to the cluster.

        igniteClient.cluster().state(ClusterState.ACTIVE);
        IgniteCluster cluster = igniteClient.cluster();
        ClusterGroup remoteGroup = cluster.forRemotes();

        ClusterMetrics metrics = remoteGroup.metrics();

        System.out.println("Total CPUs: " + metrics.getTotalCpus());
        System.out.println("Total Heap Memory: " + metrics.getHeapMemoryTotal());
        System.out.println("Heap Memory Initialized: " + metrics.getHeapMemoryInitialized());
        System.out.println("Heap Memory Used: " + metrics.getHeapMemoryUsed());
        System.out.println("Total Nodes in Cluster: " + metrics.getTotalNodes());

        // Iterate through all caches and gather details
        igniteClient.cacheNames().forEach(cacheName -> {
            IgniteCache<?, ?> cache = igniteClient.cache(cacheName);
            CacheConfiguration<?, ?> cacheConfig = cache.getConfiguration(CacheConfiguration.class);

            System.out.println("Cache Name: " + cacheName);
            System.out.println("Memory Occupied: " + cache.localSize());
            System.out.println("Cache Size: " + cache.size());
            System.out.println("Cache Hits: " + cache.metrics().getCacheHits());
            System.out.println("Cache Misses: " + cache.metrics().getCacheMisses());
            System.out.println("Average Get Time: " + cache.metrics().getAverageGetTime());
            
            System.out.println();

Is the above method correct. It shows the cache names in the servers but not the memory occupied by the cache and the persistent memory used by the caches.

Total CPUs: 12
Total Heap Memory: 4294967296
Heap Memory Initialized: 4294967296
Heap Memory Used: 115574800
Total Nodes in Cluster: 1
Cache Name: poswavierCache
Memory Occupied: 0
Cache Size: 131503
Cache Hits: 0
Cache Misses: 0
Average Get Time: 0.0

You can see that the code gets the cache name and size from the server but what I want is the amount of persistence storage used by the server.


Solution

  • Storage usage isn't recorded at the cache level. To find that, you need to look at data region metrics. Note that you also need to ensure that statistics/metrics are enabled. This is a cache and data region-specific property.