Gnuplot vmstat

Gnuplot vmstat
After you installed following packages:
apt-get install gnuplot ttf-bitstream-vera sharutils |
you can run collect-data script:
1 2 3 4 5 | DIR= '/var/tmp' PREFIX= 'vmstat' HOSTNAME=` hostname ` SLEEPTIME= '60' vmstat -n -S M $SLEEPTIME | while read line; do LOGFILE= " ${DIR}/${PREFIX}_${HOSTNAME}_`date '+%Y-%m-%d'`.log" ; echo "`date '+%T ' `$line" >> $LOGFILE; done & |
Crontabize the plotting script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | #!/bin/bash DIR= '/var/tmp' PREFIX= 'vmstat' HOSTNAME=` hostname ` MAX_MEMORY=` free -m | awk 'NR==2 {print $2}' | head ` SCALE=` echo "scale=0;$MAX_MEMORY/10" | bc ` if [ -n "$1" ] then DATE=` date '+%Y-%m-%d' -r $1` DATA= "$1" else DATE=` date -- date = "-1 day" '+%Y-%m-%d' ` DATA= "${DIR}/${PREFIX}_${HOSTNAME}_${DATE}.log" fi DATA_PLOT=` dirname $DATA`/` basename $DATA .log`.png gnuplot << EOF set terminal png size 1920,1200 font '/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf' 9 set lmargin 10 set tmargin 3 set rmargin 5 set bmargin 4 set border 3 set grid set output "${DATA_PLOT}" set xdata time set timefmt "%H:%M:%S" set format x "%H:%M:%S" set xlabel "Time" set ylabel "Value" set multiplot layout 2, 2 title "${HOSTNAME} - ${DATE}" # set size 0.5, 0.5; set origin 0, 0; set title "Memory" set yrange [ 0 : $MAX_MEMORY ] set ytics 0,$SCALE plot "${DATA}" using 1:4 ti "swap" w l, "${DATA}" using 1:5 ti "free" w l, "${DATA}" using 1:6 ti "buff" w l, "${DATA}" using 1:7 ti "cache" w l # set size 0.5, 0.5; set origin 0.5, 0; set title "IO" set autoscale xy set yrange [ 0 : 4000 ] set ytics 0,1000 set mytics 2 plot "${DATA}" using 1:10 ti "in" w l, "${DATA}" using 1:11 ti "out" w l # set size 0.5, 0.5; set origin 0, 0.5; set title "System" set yrange [ 0 : 5000 ] set ytics 0,1000 set mytics 2 plot "${DATA}" using 1:12 ti "in" w l, "${DATA}" using 1:13 ti "cs" w l # set size 0.5, 0.5; set origin 0.5, 0.5; set title "Cpu" set yrange [ 0 : 100 ] set ytics 0,10 set mytics 2 plot "${DATA}" using 1:14 ti "user" w l, "${DATA}" using 1:15 ti "system" w l, "${DATA}" using 1:16 ti "idle" w l, "${DATA}" using 1:17 ti "wait" w l unset multiplot EOF rm -f $TEMPFILE exit 0 |
configure your report program and run it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | #!/bin/bash TEMPFILE=`mktemp -p /tmp/ ` trap "rm -f ${TEMPFILE}; exit 1" INT HOSTNAME=` hostname ` DATE=` date -- date = "-1 day" '+%Y-%m-%d' ` DIR= '/var/tmp' PREFIX= 'vmstat' DATA= "${DIR}/${PREFIX}_${HOSTNAME}_${DATE}.log" DATA_PLOT=${DIR}/` basename $DATA .log`.png IP=` /sbin/ifconfig | grep -C 1 eth| grep 'inet ' | awk { 'print $2' }| cut -d ":" -f2` MAILING_LIST= 'santi@*****.**' LOG= '1' MAIL= '1' MOVE= '1' RETENTION= '+30' DEST_DIR= '/var/www/blabla/doc_root/vmstat/' ########## RED= '\033[31;1m' GREEN= '\033[32;1m' BOLD= '\033[1m' DEFAULT= '\033[0m' ########## if [ "$MAIL" - eq '1' ] then SUBJECT= "Report vmstat $HOSTNAME" MESSAGE= "$DATE\n\nMacchina: $HOSTNAME - $IP\n" echo "$MESSAGE" >> "$TEMPFILE" echo "Email inviata a: ${BOLD}${MAILING_LIST}${DEFAULT}" if [ "$LOG" - eq '1' ] then ( cat "$TEMPFILE" ; uuencode "${DATA}" "${DATA}" ; uuencode "${DATA_PLOT}" "${DATA_PLOT}" ; ) | mailx -s "$SUBJECT" "$MAILING_LIST" else ( cat "$TEMPFILE" ; uuencode "${DATA_PLOT}" "${DATA_PLOT}" ; ) | mailx -s "$SUBJECT" "$MAILING_LIST" fi fi if [ "${MOVE}" - eq '1' ] then mv ${DATA_PLOT} ${DEST_DIR} fi [ "$LOG" - eq '1' ] && echo "Logging is ${GREEN}ON${DEFAULT}" || echo "Logging is ${RED}OFF${DEFAULT}" [ "$MAIL" - eq '1' ] && echo "Mailing is ${GREEN}ON${DEFAULT}" || echo "Mailing is ${RED}OFF${DEFAULT}" [ "$MOVE" - eq '1' ] && echo "Moving log is ${GREEN}ON${DEFAULT}" || echo "Moving log is ${RED}OFF${DEFAULT}" find $DEST_DIR -mtime $RETENTION -iname '*.png' - exec rm -f {} \; rm -f $TEMPFILE exit 0 |
Actually, those scripts are running on this machine, so you can see results below:
Share This