【问题标题】:Ehcache statisticsehcache 统计
【发布时间】:2014-10-22 09:47:35
【问题描述】:

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

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

例如获取StatisticsGateway对象如下:

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

如何获取 SampledCache 对象?

提前致谢!

【问题讨论】:

    标签: caching statistics ehcache


    【解决方案1】:

    迟到的答案 :) 它可能对其他人有所帮助。

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

    【讨论】:

      【解决方案2】:

      SampleCache 充当装饰器对象。基本上,您创建一个 SampledCache 实例并将一个 Cache 实例作为后备缓存传递。后备缓存是您需要统计信息的缓存,在您的情况下是缓存实例。类似的东西

      SampledCache sampledCache = new SampledCache(cache);

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

      【讨论】:

        猜你喜欢
        • 2011-01-01
        • 2018-06-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-23
        • 2015-08-18
        • 1970-01-01
        相关资源
        最近更新 更多