Skip to content

Instantly share code, notes, and snippets.

@artbikes
Created March 7, 2012 23:21
Show Gist options
  • Save artbikes/1997147 to your computer and use it in GitHub Desktop.
Save artbikes/1997147 to your computer and use it in GitHub Desktop.
Java trace of running logstash instance
#!/bin/bash
#---
# take a dump of logstash process before restarting
#---
JSTACK=/usr/bin/jstack
JPS=/usr/bin/jps
APP=logstash
NOW=`date +%s`
OUTFILE=/var/log/logstash/$APP-trace-$NOW
cat >> $OUTFILE <<EOT
#########
# STATS #
#########
EOT
top -b -n1 -H | awk /java/ | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" >> $OUTFILE
cat >> $OUTFILE <<EOT
###############
# PIDS IN HEX #
###############
EOT
awk '/^[0-9]/{ printf "0x%x\n", $1 }' $OUTFILE >> $OUTFILE
cat >> $OUTFILE <<EOT
#########
# STACK #
#########
EOT
PROCESS=`$JPS -l | awk "/$APP/"'{ print $1 }'`
$JSTACK $PROCESS >> $OUTFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment