Last active
August 29, 2015 14:12
-
-
Save olivergondza/6627fbcb86c2f3df1b22 to your computer and use it in GitHub Desktop.
jps-monitor
This file contains 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/sh | |
# Make periodic snapshots of running java processes. | |
# | |
# ./jps-monitor.sh jmap -heap | |
# ./jps-monitor.sh jmap -heap %s # PID of monitored process will be used for %s | |
target="jps-monitor/" | |
rm -rf $target | |
mkdir -p $target | |
cmd_pattern="$@" | |
while true; do | |
jps -lmvV | while read line ; do | |
# Skip jps itself | |
if grep -q sun.tools.jps.Jps <<< "$line"; then | |
continue; | |
fi | |
# Start logging new process | |
pid=`cut -d ' ' -f 1 <<< "$line"` | |
log="$target/$pid" | |
if [ ! -f $log ]; then | |
printf "$line\n" > $log | |
fi | |
cmd=`printf "$cmd_pattern" $pid` | |
if [ "$cmd" = "$cmd_pattern" ]; then | |
cmd="$cmd_pattern $pid" | |
fi | |
echo >> $log | |
date --rfc-3339=ns >> $log | |
$cmd >> $log 2>&1 | |
sleep 1 | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment