Skip to content

Instantly share code, notes, and snippets.

@cheecheeo
Created March 14, 2012 19:46
Show Gist options
  • Save cheecheeo/2038969 to your computer and use it in GitHub Desktop.
Save cheecheeo/2038969 to your computer and use it in GitHub Desktop.
JMX MBean dumper
#!/bin/bash
function usage() {
cat <<USAGE
usage: $0 options
Dump all beans (and values) from a JMX server.
OPTIONS:
-h Show this message
-l host:port of jmxserver (default: localhost:9991)
-j jmxterm jarfile (default: jmxterm-1.0-alpha-4-uber.jar)
USAGE
}
HOSTPORT='localhost:9991'
JMXTERM='jmxterm-1.0-alpha-4-uber.jar'
while getopts "hl:j:" OPTION; do
case $OPTION in
h) usage
exit
;;
l) HOSTPORT=$OPTARG
;;
j) JMXTERM=$OPTARG
;;
*) usage
exit 1
;;
esac
done
function quote_spaces() {
echo $* | sed -e 's/ /\\ /g'
}
echo beans | java -jar ${JMXTERM} -l ${HOSTPORT} -v silent -n |
while read bean; do
quoted_bean=$(quote_spaces $bean)
echo "get -b $quoted_bean *"
done | java -jar ${JMXTERM} -l ${HOSTPORT} -n 2>&1 | grep -v '^[[:space:]]*$' | grep -v 'Welcome to JMX terminal. Type "help" for available commands.' | sed 's/^/\t/;s/^\t#mbean = /#mbean = /'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment