Ehcache 统计信息

3
我希望在运行服务器时能够查看Ehcache的所有统计信息。 在文档中,我找到了一些对象,例如“StatisticsGateway”和“SampledCache”。我正在使用ehcache 2.9版本。 使用StatisticsGateway获取的统计信息是不完整的。使用SampledCache对象可以获取更多统计信息,但是没有描述如何以某种方式检索该对象。 例如,获取StatisticsGateway对象的方式如下:
Cache cache = cacheManager.getCache("name");
StatisticsGateway statistic = cache.getStatistics();
statistic.cacheHitCount() etc.

如何获取SampledCache对象?

提前感谢!

2个回答

3

晚回复 :) 这可能会对其他人有所帮助。

您可以使用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>

1

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

SampledCache sampledCache = new SampledCache(cache);

您可以在sampledCache上调用方法以获取所需的统计信息。这里创建了一个简单的示例 http://www.ashishpaliwal.com/blog/2015/01/using-ehcache-sampledcache/


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接