简体   繁体   English

JMX监视EhCache服务器MBean

[英]JMX monitoring EhCache Server MBeans

I have a Tomcat instance where I have deployed the ehcache-server. 我有一个Tomcat实例,在其中部署了ehcache-server。 Now I make rest requests to put/get elements from my standalone Java class. 现在,我发出休息请求以放置/获取独立Java类中的元素。 Everything works as expected. 一切正常。

Now I would like to monitor the Cache. 现在,我想监视缓存。 I understand ehcache-server provides the mbeans of multiple classes. 我了解ehcache-server提供了多个类的mbean。 But I can barely find any information on how to register these mbeans. 但是我几乎找不到有关如何注册这些mbean的任何信息。

When I start the jconsole, I can see the Tomcat instance and connect to it. 启动jconsole时,可以看到Tomcat实例并连接到它。 But I do not see any classes (net.sf.ehache.*) of ehcache-server. 但是我看不到ehcache-server的任何类(net.sf.ehache。*)。

The documentation says I could use function registerMBeans to register the mbeans. 文档说我可以使用函数registerMBeans来注册mbean。 But how do I call a method in a web application from my standalone Java application? 但是,如何从独立的Java应用程序中调用Web应用程序中的方法?

I am afraid I am completely misunderstanding this. 恐怕我完全误会了。 I could use some pointers on how to register the mbeans and do the monitoring. 我可以使用一些有关如何注册mbean和进行监视的指针。

Thanks in advance. 提前致谢。

It is actually pretty simple. 实际上很简单。 Add this below config file in your web project 在您的Web项目中将其添加到配置文件下面

@Configuration
@EnableCaching
public class SpringCachePocConfig implements CachingConfigurer {

    net.sf.ehcache.CacheManager newCacheManager;

    @Bean(destroyMethod = "shutdown")
    public net.sf.ehcache.CacheManager ehCacheManager() {
        //Construct you cache here.

        net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration();
        config.addCache(<Your cache>);

        this.newCacheManager = new net.sf.ehcache.CacheManager(config);
        return newCacheManager;
    }


    @Bean
    public ManagementService managementService() {
        return new ManagementService(ehCacheManager(), mbeanServer(), true, true, true, true);

    }


    @Bean
    @Override
    public CacheManager cacheManager() {
        return new EhCacheCacheManager(ehCacheManager());
    }


    @Bean
    public MBeanServer mbeanServer() {
        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
        return mBeanServer;   
    }

    @PostConstruct
    public void init() {
        ManagementService.registerMBeans(ehCacheManager(), mbeanServer(), true, true, true, true);
    }


}

The init() function will register your MBeans. init()函数将注册您的MBean。 Dont forget to add @PostConstruct annotation above your init() method 不要忘记在init()方法上方添加@PostConstruct批注

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM