2014-10-22 174 views
2

我希望在运行服务器时查看Ehcache的所有统计信息。 在文档中我找到了诸如“StatisticsGateway”和“SampledCache”之类的对象。我正在使用ehcache 2.9。Ehcache统计信息

通过使用StatisticsGateway获取不完整的统计信息。当使用SampledCache对象时,我可以获得更多的统计信息,但无法以某种方式描述检索对象。

例如,获得StatisticsGateway对象如下:

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

如何获得SampledCache对象?

在此先感谢!

回答

1

SampleCache充当装饰器对象。基本上你创建一个SampledCache的实例并将一个Cache实例作为后备缓存。支持Cache是​​您需要统计的缓存,在您的情况下是缓存实例。像

SampledCache sampledCache = new SampledCache(cache);

东西,你可以调用sampledCache方法,从而获得所需的统计数据。在这里创建一个简单的例子http://www.ashishpaliwal.com/blog/2015/01/using-ehcache-sampledcache/

2

最后回答:)它可能会帮助其他人。

您可以从java/bin目录中使用jconsole.exe。 Jconsole可以显示你的统计数据。

您可能需要添加JMX支持看在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> 
统计