Skip to content

Instantly share code, notes, and snippets.

@ghidinelli
Created August 20, 2015 17:50
Show Gist options
  • Save ghidinelli/a57dd23c03005f0980e8 to your computer and use it in GitHub Desktop.
Save ghidinelli/a57dd23c03005f0980e8 to your computer and use it in GitHub Desktop.
jstatall.sh - shell script for displaying jstat metrics of two JREs side by side in the console
#!/bin/bash
# bug in JDK > 1.7 u75 where root can't see non-root JVMs, so specify the username of the process owner (lazy approach)
USER=nobody
# Tweak the grep for whatever JVM-based applications you're looking to monitor
INST1=`/bin/ps -ef |/bin/grep "INSTANCE1/bin/cf-bootstrap.jar" | /bin/grep -v grep | /usr/bin/awk -F" " '{print $2}'|/usr/bin/head -1`
INST2=`/bin/ps -ef |/bin/grep "INSTANCE2/bin/cf-bootstrap.jar" | /bin/grep -v grep | /usr/bin/awk -F" " '{print $2}'|/usr/bin/tail -1`
# catch ctrl-c and clean up jstat
trap ctrl_c INT
function ctrl_c() {
/usr/bin/pkill jstat
exit
}
echo "PIDS: INSTANCE1 = $INST1, INSTANCE2 = $INST2"
/usr/bin/paste <(/usr/bin/sudo -u $USER /usr/java/latest/bin/jstat -gcutil -t -h100 $INST1 5000) <(/usr/bin/sudo -u $USER /usr/java/latest/bin/jstat -gcutil -t -h100 $INST2 5000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment