For the latest stable version, please use Spring Data MongoDB 4.4.3! |
JMX support
The JMX support for MongoDB exposes the results of running the 'serverStatus' command on the admin database for a single MongoDB server instance. It also exposes an administrative MBean, MongoAdmin
, that lets you perform administrative operations, such as dropping or creating a database. The JMX features build upon the JMX feature set available in the Spring Framework. See here for more details.
MongoDB JMX Configuration
Spring’s Mongo namespace lets you enable JMX functionality, as the following example shows:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/data/mongo
https://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- Default bean name is 'mongo' -->
<mongo:mongo-client host="localhost" port="27017"/>
<!-- by default look for a Mongo object named 'mongo' -->
<mongo:jmx/>
<context:mbean-export/>
<!-- To translate any MongoExceptions thrown in @Repository annotated classes -->
<context:annotation-config/>
<bean id="registry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean" p:port="1099" />
<!-- Expose JMX over RMI -->
<bean id="serverConnector" class="org.springframework.jmx.support.ConnectorServerFactoryBean"
depends-on="registry"
p:objectName="connector:name=rmi"
p:serviceUrl="service:jmx:rmi://localhost/jndi/rmi://localhost:1099/myconnector" />
</beans>
The preceding code exposes several MBeans:
-
AssertMetrics
-
BackgroundFlushingMetrics
-
BtreeIndexCounters
-
ConnectionMetrics
-
GlobalLockMetrics
-
MemoryMetrics
-
OperationCounters
-
ServerInfo
-
MongoAdmin
The following screenshot from JConsole shows the resulting configuration:
