Skip to content

Instantly share code, notes, and snippets.

@nicholashagen
Created January 29, 2013 16:30
Show Gist options
  • Save nicholashagen/4665567 to your computer and use it in GitHub Desktop.
Save nicholashagen/4665567 to your computer and use it in GitHub Desktop.
JMX via Groovy with Authentication
import javax.management.*
import javax.management.remote.*
def creds = [ 'username', 'password' ] as String[]
def env = [ (JMXConnector.CREDENTIALS) : creds ]
def serverUrl = 'service:jmx:rmi:///jndi/rmi://hostname:port/jmxrmi'
def server = JMXConnectorFactory.connect(new JMXServiceURL(serverUrl), env).MBeanServerConnection
new GroovyMBean(server, 'java.lang:type=Threading').dumpAllThreads(true, true).each { thread ->
println "THREAD: ${thread.threadName}"
}
true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment