I've set hibernate.generate_statistics=true and now need to register the mbeans so I can see the statistics in the jmx console. I can't seem to get anywhere and this doesn't seem like it should be such a difficult problem. Maybe I'm making things overcomplicated, but in any case so far I've tried:
- I copied EhCacheProvider and had it instantiate an extended version of CacheManager which overloaded init() and called ManagementService.registerMBeans(...) after initialization. The code all ran fine until the actual call to registerMBeans(...) which would cause the provider initialization to fail with a generic error (unfortunately I didn't write it down.) This approach was motivated by the methods used in this liferay performance walkthrough.
- I created my own MBean with a start method that ran similar code to this example of registering ehcache's jmx mbeans. Everything appeared to work correctly and my mbean shows up in the jmx console but nothing for net.sf.ehcache.
- I've since upgraded ehcache to 1.5 (we were using 1.3, not sure if that's specific to jboss 4.2.1 or just something we chose ourselves) and changed to using the SingletonEhCacheProvider and trying to just manually grab the statistics instead of dealing with the mbean registration. It hasn't really gone any better though; if I call getInstance() the CacheManager that's returned only has a copy of StandardQueryCache, but jboss logs show that many other caches have been initialized (one for each of the cached entities in our application.)
EDIT: Well I have figured out one thing...connecting via JConsole does reveal the statistics mbeans. I guess ManagementFactory.getPlatformMBeanServer() doesn't give you the same mbean server as jboss is using. Anyway it looks like I'm encountering a similar problem as when I tried collecting the statistics manually, because I'm getting all zeros even after clicking through my app for a bit.