DataNucleus allows a user to enable various MBeans internally. These can then be used for monitoring the number of datastore calls etc.
The simplest way to monitor DataNucleus is to use its API for monitoring. Internally there are several MBeans (as used by JMX) and you can navigate to these to get the required information. To enable this set the persistence property datanucleus.enableStatistics to true . There are then two sets of statistics; one for the EMF and one for each EM. You access these as follows
JPAEntityManagerFactory dnemf = (JPAEntityManagerFactory)emf; FactoryStatistics stats = dnemf.getNucleusContext().getStatistics(); ... (access the statistics information) JPAEntityManager dnem = (JPAEntityManager)em; ManagerStatistics stats = dnem.getExecutionContext().getStatistics(); ... (access the statistics information)
The MBeans used by DataNucleus can be accessed via JMX at runtime. More about JMX here.
An MBean server is bundled with Sun JRE since version 1.5, and you can easily activate DataNucleus MBeans registration by creating your EMF with the persistence property datanucleus.jmxType as default
Additionaly, setting a few system properties are necessary for configuring the Sun JMX implementation. The minimum properties required are the following:
java -cp TheClassPathInHere -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=8001 TheMainClassInHere
Once you start your application and DataNucleus is initialized you can browse DataNucleus MBeans using a tool called jconsole (jconsole is distributed with the Sun JDK) via the URL:
Note that the mode of usage is presented in this document as matter of example, and by no means we recommend to disable authentication and secured communication channels. Further details on the Sun JMX implementation and how to configure it properly can be found in here.
DataNucleus MBeans are registered in a MBean Server when DataNucleus is started up (e.g. upon JPA EMF instantiation). To see the full list of DataNucleus MBeans, refer to the javadocs.
To enable management using MX4J you must specify the persistence property datanucleus.jmxType as mx4j when creating the EMF, and have the mx4j and mx4j-tools jars in the CLASSPATH.