Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ehcache statistics

I would like to see all statistics for the Ehcache when I have running server. In the documentation I have found objects such as "StatisticsGateway" and "SampledCache". I'm using ehcache 2.9.

By using StatisticsGateway gets incomplete statistics. When using the SampledCache object I get more statistics, but nowhere is described in some way to retrieve the object.

For example, getting the StatisticsGateway object is as follow:

Cache cache = cacheManager.getCache("name");
StatisticsGateway statistic = cache.getStatistics();
statistic.cacheHitCount() etc.

How to get the SampledCache object?

Thanks in advance!

like image 501
Piotr Avatar asked Jun 22 '26 00:06

Piotr


2 Answers

Late answer :) it may help some one else.

You can use jconsole.exe from your java/bin directory. The Jconsole can show you the statistics.

You may need to add the JMX support to see the statistics in Jconsole

<!-- JMX for Ehcache -->
    <bean id="managementService" class="net.sf.ehcache.management.ManagementService"
        init-method="init" destroy-method="dispose">
        <constructor-arg ref="ehcache" />
        <constructor-arg ref="mbeanServer" />
        <constructor-arg index="2" value="true" />
        <constructor-arg index="3" value="true" />
        <constructor-arg index="4" value="true" />
        <constructor-arg index="5" value="true" />
    </bean>
like image 55
Sam Avatar answered Jun 23 '26 17:06

Sam


SampleCache acts as a decorator object. Basically you create an instance of SampledCache and pass a Cache instance as a backing cache. The backing Cache is the cache for which you need stats, in your case the cache instance. Something like

SampledCache sampledCache = new SampledCache(cache);

You can call methods on sampledCache to get desired stats. Created a simple example here http://www.ashishpaliwal.com/blog/2015/01/using-ehcache-sampledcache/

like image 36
Ashish Paliwal Avatar answered Jun 23 '26 17:06

Ashish Paliwal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!