In Ehcache 3.0.0, How to get the live statistics data ?

3,307 views
Skip to first unread message

lith...@gmail.com

unread,
Apr 26, 2016, 8:58:08 PM4/26/16
to ehcache-users
Environment:  Ehcache 3.0.0 / Java8.  (moving from Ehcache 2.x.x)

We had following implementation in our product for reporting live statistics data:

  //get statistics data since Ehcache 2.4.1 

  cache.setSampledStatisticsEnabled(true);

  cache.setStatisticsAccuracy(Statistics.STATISTICS_ACCURACY_NONE);

  LiveCacheStatistics stat = cache.getLiveCacheStatistics();

  // with 'stat' object, we can print/report all of following data

  log.info( stat.getCacheHitCount() );

  log.info( stat.getInMemoryHitCount() );

  log.info( stat.getOffHeapHitCount() );

  log.info( stat.getOnDiskHitCount() );

  log.info( stat.getCacheMissCount() );

  log.info( stat.getInMemoryMissCount() );

  log.info( stat.getOffHeapMissCount() );

  log.info( stat.getOnDiskMissCount() );

  log.info( stat.getSize() );

  log.info( stat.getInMemorySize() );

  log.info( stat.getOffHeapSize() );

  log.info( stat.getAverageSearchTime() );



Now I tried to find the counterpart in Ehcache 3.0.0 but couldn't figure it out.  I tried to google the solution but cannot find the sample code.

Can anyone give me some hints here?


Thanks in advance.

Louis Jacomet

unread,
Apr 27, 2016, 2:51:11 PM4/27/16
to ehcache-users
Hi,

Ehcache 3.0 does not have a public statistic API.

If used through the javax.caching bridge (JSR-107), there is something defined through an MBean.

We took the decision of not having a public API in the first version as we were not sure what we would want to expose through it.

Regards,
Louis

--
You received this message because you are subscribed to the Google Groups "ehcache-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-user...@googlegroups.com.
To post to this group, send email to ehcach...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ehcache-users/c9b2ac45-9026-4670-81b5-7b93e5e94f4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

lith...@gmail.com

unread,
Apr 27, 2016, 4:52:34 PM4/27/16
to ehcache-users
I see. 
Thanks Louis!
Message has been deleted

Louis Jacomet

unread,
May 8, 2016, 2:34:39 AM5/8/16
to ehcache-users
Yes, that is correct. In order to get MBeans registered, you have to use JSR-107 and configure it properly - see methods on CompleteConfiguration.

On Thu, Apr 28, 2016 at 7:09 PM <lith...@gmail.com> wrote:
Using ehcache 2.x, I was able to browse MBean of 'net.sf.ehcache':
  'net.sf.ehcache'
    -> 'SampledCache'
      -> 'myCache'  
    -> 'SampledCacheManager'
      -> 'myCacheManager'
  
but switched to ehcache 3.0.0, I don't see 'org.ehcache' showing in my MBean browser.

For viewing those statistics data through a MBean, I have to use 'javax.cache' bridge way in my coding (change code to use JSR107's date types)?

Thanks in advance.



--
You received this message because you are subscribed to the Google Groups "ehcache-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-user...@googlegroups.com.
To post to this group, send email to ehcach...@googlegroups.com.

wilming...@gmail.com

unread,
Jun 8, 2016, 2:33:15 PM6/8/16
to ehcache-users
+1 for bringing back Statistics.  I'd like to use ehcache 3.0 because it has the functionality to specify the heap size with memory settings and not just number of entries.  I don't think it's possible to use this and JSR-107 concurrently, correct?  Thanks!

Louis Jacomet

unread,
Jun 8, 2016, 2:39:42 PM6/8/16
to ehcache-users
Hi,

What kind of stats would you really need? Is the JSR-107 list comprehensive enough?

Regarding using byte sized in a JSR-107 context, you will have to resort to provider specific configuration but this is certainly possible.


Regards,
Louis

wilming...@gmail.com

unread,
Jun 9, 2016, 8:31:59 AM6/9/16
to ehcache-users
I basically want enough information so I can build graphs to display to an admin.  It would basically show how much of the allocated memory is being used in the cache.  I've switched my code over to use the javax.cache.Cache and javax.cache.CacheManager object but still use the underlying ehcache configuration.  Is it possible to still persist data to disk using this method?  Normally I would use the CacheManagerBuilder to specify a persistent cache (giving it a directory location) when creating an ehcache CacheManager.

Louis Jacomet

unread,
Jun 14, 2016, 2:56:04 AM6/14/16
to ehcache-users
You can certainly use Ehcache configuration for setting up javax.cache CacheManager and Cache.


Regards,
Louis

Gabriel Magniez

unread,
Jun 17, 2016, 5:26:52 PM6/17/16
to ehcache-users
Hi,
I have the same issue, I'm trying an offheap cache but it is very hard to size it as there id no way to see the occupied size, the jvm reports that all the direct buffers are used

wilming...@gmail.com

unread,
Jun 21, 2016, 2:07:44 PM6/21/16
to ehcache-users
Thanks for the info.  I have my code switched to use the javax cache with Ehcache as the underlying cache.  What's the best mechanism to get to the statistics from there?
Reply all
Reply to author
Forward
0 new messages