Created
February 28, 2018 15:44
-
-
Save squarepegsys/faff5dff8666ffddaa06cd0ea14752d8 to your computer and use it in GitHub Desktop.
A quick and dirty Groovy script to monitor Mongo connections for a short time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.management.remote.* | |
import javax.management.* | |
import groovy.jmx.builder.* | |
// see https://mongodb.github.io/mongo-java-driver/3.0/driver/reference/management/monitoring/ | |
attrs = ['CheckedOutCount','MinSize','MaxSize','WaitQueueSize','Size'] | |
def print_mbeans(def mbeans) { | |
def webBean = mbeans.queryNames(new ObjectName('org.mongodb.driver:*'), null).find { | |
name-> | |
def values = [ new Date() as String, name.getKeyProperty('clusterId')] | |
attrs.each { attr-> | |
values<<mbeans.getAttribute(name,attr) | |
} | |
println values.join(",") | |
} | |
} | |
// Setup JMX connection. | |
def connection = new JmxBuilder().client(port: 8991, host: 'localhost') | |
connection.connect() | |
// Get the MBeanServer. | |
def mbeans = connection.MBeanServerConnection | |
print "Date,ClusterId," | |
println attrs.join(",") | |
// change 10 to however many seconds you want this to run | |
(1..10).each { | |
print_mbeans(mbeans) | |
Thread.sleep(1000) | |
} | |
print "Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment