com.mongodb.tools
Class ConnectionPoolStat

java.lang.Object
  extended by com.mongodb.tools.ConnectionPoolStat

public class ConnectionPoolStat
extends Object

A simple class that formats Mongo Java driver connection pool statistics in an easily-accessible JSON format. It can be used to get statistics on connection pool in the same VM by using the no-args constructor, or in any VM by using the constructor that takes an MBeanServerConnection.

This class also exposes a command line interface modeled after mongostat. For usage, run:

   java -cp mongo.jar com.mongodb.util.management.jmx.ConnectionPoolStat --help}


MongoDB Doc Links

Constructor Summary
ConnectionPoolStat()
          Use the platform MBean server.
ConnectionPoolStat(MBeanServerConnection mBeanConnection)
          Use the given MBean server connection to access statistics for connection pools.
 
Method Summary
 String getStats()
          Gets the statistics for all Mongo connection pools registered with the MBean server used by this instance.
static void main(String[] args)
          Command line interface for displaying connection pool stats.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionPoolStat

public ConnectionPoolStat(MBeanServerConnection mBeanConnection)
Use the given MBean server connection to access statistics for connection pools.

Parameters:
mBeanConnection - the MBean server to connect to

ConnectionPoolStat

public ConnectionPoolStat()
Use the platform MBean server. This is useful if you want to access statistics for connection pools in the same virtual machine.

See Also:
ManagementFactory.getPlatformMBeanServer()
Method Detail

getStats

public String getStats()
                throws JMException,
                       IOException
Gets the statistics for all Mongo connection pools registered with the MBean server used by this instance. The format will always be JSON, but the specific JSON fields may change in a future release. An example of the output, which should not be taken as a specification:
   { pools : [
     { objectName: 'com.mongodb:type=ConnectionPool,host=localhost/127.0.0.1,port=27018,instance=1',
       host: 'localhost', port: 27018, maxSize: 10, total: 10, inUse: 3,
       inUseConnections: [
         { namespace: 'FindContention.test', opCode: 'OP_QUERY', query: { }, numDocuments: 1, threadName: 'pool-2-thread-19', durationMS: 843, localPort: 64062 },
         { namespace: 'FindContention.test', opCode: 'OP_QUERY', query: { }, numDocuments: 1, threadName: 'pool-2-thread-1', durationMS: 4331, localPort: 64095 },
         { namespace: 'FindContention.test', opCode: 'OP_QUERY', query: { }, numDocuments: 1, threadName: 'pool-2-thread-16', durationMS: 4343, localPort: 64087 }
       ]
     },
     { objectName: 'com.mongodb:type=ConnectionPool,host=localhost/127.0.0.1,port=27017,instance=1',
       host: 'localhost', port: 27017, maxSize: 10, total: 10, inUse: 2,
       inUseConnections: [
         { namespace: 'FindContention.test', opCode: 'OP_QUERY', query: { }, numDocuments: 1, threadName: 'pool-2-thread-5', durationMS: 920, localPort: 64093 },
         { namespace: 'FindContention.test', opCode: 'OP_QUERY', query: { }, numDocuments: 1, threadName: 'pool-2-thread-11', durationMS: 1468, localPort: 64068 },
       ]
     }
    ]
   }

Returns:
JSON-formatted stats for all connection pools registered in JMX
Throws:
JMException - for any JMX-related exceptions
IOException - for any I/O exceptions

main

public static void main(String[] args)
                 throws Exception
Command line interface for displaying connection pool stats. In order to connect to a remote JMX server to get these stats, currently you must set com.sun.management.jmxremote.port system property on the remote server and specify that port using the --port argument.

Parameters:
args - program arguments
Throws:
Exception - JMX-related exceptions
See Also:
printUsage()