Vmstat.sh

From PeformIQ Upgrade
Jump to navigation Jump to search

Automated vmstat Collector

#!/bin/sh
#
#--------------------------------------------------------------------------


function datetime {
    while read LINE ; do
        DATE=`date "+%Y-%m-%d %H:%M:%S"`
        printf "${DATE}  ${LINE}\n"
    done
}

#--------------------------------------------------------------------------

HOST=`hostname | sed 's/\..*//'`
#HOST=lnfsnd52

echo $HOST

PERIOD=720  # Minutes
DELAY=60    # Seconds

#--------------------------------------------------------------------------

SECONDS=`expr $PERIOD '*' 60`
CNT=`expr $SECONDS '/' $DELAY`

TS_FNAME=`date "+%Y%m%d_%H%M"`
TS_START=`date "+%Y-%m-%d %H:%M:%S"`

LOG="${HOST}_${TS_FNAME}.vmstat"

echo "Processing to file - $LOG"

#--------------------------------------------------------------------------

echo "==> Count: $CNT   Delay: $DELAY"       >  $LOG
echo "==> Start: $TS_START"                  >> $LOG
echo                                         >> $LOG

vmstat $DELAY $CNT  | datetime               >> $LOG &

#--------------------------------------------------------------------------