-
-
Save hchoroomi/3278470 to your computer and use it in GitHub Desktop.
Reading some JMX MBeans from a Scala script
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
#!/bin/sh | |
exec scala $0 "$@" | |
!# | |
import scala.collection.JavaConversions._ | |
import java.lang.management.{ManagementFactory, MemoryMXBean} | |
import java.net.URI | |
import javax.management.JMX | |
import javax.management.remote.{JMXConnectorFactory, JMXServiceURL} | |
if (args.length < 1) { | |
println("Usage: jmx.scala HOST:PORT ...") | |
System.exit(1) | |
} | |
for (jmxPeer <- args) { | |
val jmxUrl = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://%s/jmxrmi".format(jmxPeer)) | |
val jmxc = JMXConnectorFactory.connect(jmxUrl, null) | |
val connection = jmxc.getMBeanServerConnection | |
val memProxy = ManagementFactory.newPlatformMXBeanProxy(connection, ManagementFactory.MEMORY_MXBEAN_NAME, | |
classOf[MemoryMXBean]) | |
println("%s: %s".format(jmxPeer, memProxy.getHeapMemoryUsage)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment