Created
May 17, 2017 09:27
-
-
Save bdelbosc/b52c1479ef12eb14308b680e15ee25ae to your computer and use it in GitHub Desktop.
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/sh -x | |
HERE=`dirname $0` | |
HERE=`cd $HERE; pwd` | |
KSAR_JAR=$HERE/kSar.jar | |
LOG_PATH=$HERE/log | |
SAR_FILE=$LOG_PATH/bench.sar | |
SAR_PID=$LOG_PATH/sar.pid | |
mkdir -p $LOG_PATH | |
do_start() { | |
[ -f $SAR_PID ] && do_stop | |
[ -f $SAR_FILE ] && rm -f $SAR_FILE | |
echo | |
echo "Starting sar monitoring..." | |
sar -d -o $SAR_FILE 1 1000000 > /dev/null 2>&1 & | |
echo $! > $SAR_PID | |
sleep 5 | |
echo "Started pid $!." | |
} | |
do_stop() { | |
echo "Stopping sar..." | |
if [ ! -f $SAR_PID ]; then | |
echo "No pid file $SAR_PID found." | |
exit 1 | |
fi | |
pid=`cat $SAR_PID` | |
ps $pid > /dev/null | |
if [ $? = 0 ]; then | |
sleep 3 | |
kill $pid | |
echo "Sar stopped." | |
rm -f $SAR_PID | |
exit 0 | |
else | |
echo "No sar running." | |
rm -f $SAR_PID | |
exit 1 | |
fi | |
} | |
do_status() { | |
if [ -f $SAR_PID ]; then | |
pid=`cat $SAR_PID` | |
ps $pid > /dev/null | |
if [ $? = 0 ]; then | |
echo "Sar is running" | |
exit 0 | |
fi | |
fi | |
echo "No sar running." | |
exit 1 | |
} | |
do_report() { | |
echo "### Building SAR report ----------------------------" | |
# this one works !!! | |
# /usr/lib/jvm/java-6-sun/bin/java -jar /usr/local/kSar-5.0.6/kSar.jar -input jboss-sar.txt -outputPDF jboss-sar.pdf | |
# | |
TAG=`date -u '+%F_%H-%M-%S'` | |
REPORT=sar-report-$TAG.pdf | |
LC_ALL=C sar -f $SAR_FILE -A > $SAR_FILE.txt | |
java -jar $KSAR_JAR -input $SAR_FILE.txt -outputPDF $REPORT || exit -2 | |
echo "$REPORT created." | |
} | |
case "$1" in | |
start) | |
do_start | |
;; | |
stop) | |
do_stop | |
;; | |
restart) | |
do_stop | |
do_start | |
;; | |
status) | |
do_status | |
;; | |
report) | |
do_report | |
;; | |
*) | |
echo "usage: `basename $0` (start|stop|status|restart|report|help)" | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment