Created
July 12, 2012 19:03
-
-
Save vvuksan/3100171 to your computer and use it in GitHub Desktop.
JMX collection using command line JMX client
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/bash | |
if [ $# -ne 3 ]; then | |
echo "You need to supply both JMX host and port and metric. Exiting ..." | |
exit 1 | |
fi | |
JAVA_BIN="/usr/bin/java" | |
JMX_CMDLINE="/opt/ganglia/cmdline-jmxclient-0.10.3.jar" | |
GMETRIC_BIN="/usr/bin/gmetric -d 180" | |
APP_NAME="${1}" | |
if [ $3 = "DaemonThreadCount" -o $3 = "all" ]; then | |
TEMPFILE=`mktemp` | |
$JAVA_BIN -jar $JMX_CMDLINE - ${1}:${2} "java.lang:type=Threading" DaemonThreadCount 2>> $TEMPFILE | |
VALUE=`grep DaemonThreadCount $TEMPFILE | sed "s/.*DaemonThreadCount: //g" | cut -f2 -d:` | |
$GMETRIC_BIN -t uint16 -u threads -n ${APP_NAME}_threads -v $VALUE | |
echo "$VALUE" | |
rm -f $TEMPFILE | |
fi | |
if [ $3 = "HeapMemoryUsage" -o $3 = "all" ]; then | |
TEMPFILE=`mktemp` | |
$JAVA_BIN -jar $JMX_CMDLINE - ${1}:${2} "java.lang:type=Memory" HeapMemoryUsage 2>> $TEMPFILE | |
OUTPUT=`cat $TEMPFILE | egrep "committed:|used:" | sed "s/: /=/g"` | |
for line in $OUTPUT | |
do | |
NAME=`echo $line | cut -f1 -d=` | |
VALUE=`echo $line | cut -f2 -d=` | |
$GMETRIC_BIN -t double -u Bytes -n ${APP_NAME}_heap_$NAME -v $VALUE | |
done | |
cat $TEMPFILE | grep used | cut -f2 -d" " | |
rm -f $TEMPFILE | |
fi | |
if [ $3 = "PSPermGen" -o $3 = "all" ]; then | |
rm -f $TEMPFILE | |
$JAVA_BIN -jar $JMX_CMDLINE - ${1}:${2} "java.lang:name=PS Perm Gen,type=MemoryPool" Usage 2>> $TEMPFILE | |
OUTPUT=`cat $TEMPFILE | egrep "committed:|used:" | sed "s/: /=/g"` | |
for line in $OUTPUT | |
do | |
NAME=`echo $line | cut -f1 -d=` | |
VALUE=`echo $line | cut -f2 -d=` | |
$GMETRIC_BIN -t double -u Bytes -n ${APP_NAME}_permgen_$NAME -v $VALUE | |
echo "$VALUE" | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment