Skip to content

Instantly share code, notes, and snippets.

@laszlocsontos
Created November 25, 2014 12:55
Show Gist options
  • Save laszlocsontos/3e4da7f6066ca9b3e2e8 to your computer and use it in GitHub Desktop.
Save laszlocsontos/3e4da7f6066ca9b3e2e8 to your computer and use it in GitHub Desktop.
Gather JVM CPU usage metrics per thread
#!/bin/sh
count=30
delay=1
pid=`jps -v | grep liferay | awk '{ print $1 }'`
if [ -n "${1}" ]; then
pid=$1
fi
if [ -z "${pid}" ]; then
echo "No Liferay process found"
exit 1
fi
tmpdir="/tmp/${pid}.$(date +%Y%m%d.%H%M%S)"
mkdir -p $tmpdir
for i in `seq 1 $count`;
do
timestamp=$(date +%Y%m%d.%H%M%S)
dump_name="thread_dump_${pid}_${timestamp}.txt"
metrics_name="thread_cpu_${pid}_${timestamp}.txt"
jstack -l $pid > $tmpdir/$dump_name
pidstat -t -p $pid | sort -nr -k8 | egrep -v "^Linux|UID.*TGID" | \
awk '{ printf "%s 0x%x\n", $8, $4}' > $tmpdir/$metrics_name
sleep $delay
done
packname="${tmpdir}.zip"
echo "Creating thread dump package: ${packname}"
zip --move -r $packname $tmpdir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment