Skip to content

Instantly share code, notes, and snippets.

@nobusue
Created October 10, 2010 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nobusue/619284 to your computer and use it in GitHub Desktop.
Save nobusue/619284 to your computer and use it in GitHub Desktop.
// g100pon #42 お手軽JMXビューア
// 詳細は以下の文献を参照するとよいです
// http://groovy.codehaus.org/Groovy+JmxBuilder
// http://groovy.codehaus.org/Groovy+and+JMX
// http://download.oracle.com/javaee/1.4/api/javax/management/MBeanServerConnection.html
// http://www.javainthebox.net/laboratory/J2SE1.5/MonitoringAndManagement/JMX/JMX2.html
import groovy.jmx.builder.*
// MBean Serverに接続
// 下の例はローカル接続だが、初期プロパティを変えればリモートにもつなげられるはず
def jmx = new JmxBuilder()
def server = jmx.getMBeanServer()
// 登録されているMBean nameをすべて取得
def names = server.queryNames(null, null).toArray()
// 抜けるときはCtrl-Cで
while(true) {
// MBean一覧を表示し、入力を待つ
names.eachWithIndex{ name,index -> println "[${index}] $name" }
print '\nselect MBeans to show: '
def reader = new InputStreamReader(System.in)
def input = reader.readLine()
if(input.isInteger()) {
def index = input.toInteger()
def name = names[index]
def info = server.getMBeanInfo(name)
// 指定されたMBeanのattribute一覧を表示
info.attributes.each{
if(it.isReadable()){
try{
def value = server.getAttribute(name, it.name)
println "${it.name}: ${value}"
}catch(e){}
}
}
println ''
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment