4

I'm looking into Oracle Coherence for a client, and one of the things they are interested in is getting statistical information back from it to understand usage patterns etc.

I know I can get some information from JMX, however there is also a CacheStatistics interface provided which I'd like to get data from. However I can't see how I should go from having a cache object to getting its statistics.

The code below is my poc implementation, and I can use the 'cache' object to put and get values from the cache, is there a way to link from the cache to the associated statistics? I guess I'm missing something simple somewhere...

    NamedCache cache = CacheFactory.getCache(cacheName);
    if(cache.isActive()){
            //Wrong because there's no link to the cache..
        SimpleCacheStatistics scs = new SimpleCacheStatistics();

        long hits = scs.getCacheHits();
        System.out.println("Cache hits:" +hits+"\n   : "+scs.toString());
    }
Mast
  • 1,788
  • 4
  • 29
  • 46
MrChris
  • 117
  • 7

1 Answers1

0

If the cache is a nearcache, then you can do the following.Also check the API to get backcache to see its statistics.

if (cache instanceof NearCache) {
    System.out.println("\tstatistics :" + ((LocalCache)((NearCache)cache).getFrontMap()).getCacheStatistics());
}
Flexo
  • 87,323
  • 22
  • 191
  • 272
Kumar225
  • 227
  • 1
  • 5
  • 13
  • 2
    getCacheStatistics() for local cache is deprecated. Is there any other way to get statistics ? – Nishu Dec 07 '15 at 14:42