
# get the TOP dir if passed in
if [ "X$1" != "X" ]; then
    TOP=$1
    echo "Setting WPC TOP to $TOP"
fi

LOGDIR=$TOP/logs/diagnostic/system_status
if [ ! -d $LOGDIR ]; then
	mkdir -p $LOGDIR
fi

# source the common.functions
. $TOP/bin/diagnostic/common/common.functions

# put timestamp and version info in README.txt file
getReportHeader > $LOGDIR/README.txt


TIMEOUT=30
ITERATIONS=5

while true; do
   # Append to the file if it already exists
   if [ ! -s systemStats`date '+%m-%d-%Y'`.vmstat.out ]; then
	# ./count_descriptors.sh  | egrep -v "memory|swap"| sed -e "s%^%`date '+%m-%d-%Y-%k-%M-%S'`,%" >> $LOGDIR/systemStats`date '+%m-%d-%Y'`.descriptors.out

   	# traceroute ndc-pimdb1 2>/dev/null | sed -e "s%^%`date '+%m-%d-%Y-%k-%M-%S'` %" >> $LOGDIR/systemStats`date '+%m-%d-%Y'`.traceroute.out

   	vmstat 5 $ITERATIONS 2>/dev/null | egrep -v "memory|swap"| sed -e "s%^%`date '+%m-%d-%Y-%k-%M-%S'` %" >> $LOGDIR/systemStats`date '+%m-%d-%Y'`.vmstat.out

   	iostat 5 $ITERATIONS 2>/dev/null | egrep -v "tty|tin" | sed -e "s%^%`date '+%m-%d-%Y-%k-%M-%S'` %" >> $LOGDIR/systemStats`date '+%m-%d-%Y'`.iostat.out

   	# prstat -n 10 1 1     | egrep -v "processes|USERNAME" | sed -e "s%^%`date '+%m-%d-%Y-%k-%M-%S'` %" >> $LOGDIR/systemStats`date '+%m-%d-%Y'`.prstat.out

   	# java -classpath $CLASSPATH:`pwd` TestDBQueryTime wpc \
        #                    	wpc \
        #                    	jdbc:oracle:thin:@ndc-pimdb1:1521:wmpmpp1 \
        #                    	oracle.jdbc.driver.OracleDriver \
        #                    	'select * from itm' \
        #                    	20000 \
        #                    	10  | sed -e "s%^%`date '+%m-%d-%Y-%k-%M-%S'`,%" >>  $LOGDIR/systemStats`date '+%m-%d-%Y'`.TestDBQuery.out

    # create a new file with the header info if the files does not already exist
    else
	# ./count_descriptors.sh  | egrep -v "memory|swap"| sed -e "s%^%`date '+%m-%d-%Y-%k-%M-%S'`,%" > $LOGDIR/systemStats`date '+%m-%d-%Y'`.descriptors.out

	# traceroute ndc-pimdb1 2>/dev/null | sed -e "s%^%`date '+%m-%d-%Y-%k-%M-%S'` %" > $LOGDIR/systemStats`date '+%m-%d-%Y'`.traceroute.out

	vmstat 5 $ITERATIONS 2>/dev/null | sed -e "s%^%`date '+%m-%d-%Y-%k-%M-%S'` %" > $LOGDIR/systemStats`date '+%m-%d-%Y'`.vmstat.out

	iostat 5 $ITERATIONS 2>/dev/null | sed -e "s%^%`date '+%m-%d-%Y-%k-%M-%S'` %" > $LOGDIR/systemStats`date '+%m-%d-%Y'`.iostat.out

	# prstat -n 10 1 1| sed -e "s%^%`date '+%m-%d-%Y-%k-%M-%S'` %" > $LOGDIR/systemStats`date '+%m-%d-%Y'`.prstat.out

	# java -classpath $CLASSPATH:`pwd` TestDBQueryTime wpc \
        #                   	wpc \
        #                   	jdbc:oracle:thin:@ndc-pimdb1:1521:wmpmpp1 \
        #                   	oracle.jdbc.driver.OracleDriver \
        #                   	'select * from itm' \
        #                   	20000 \
        #                   	10  | sed -e "s%^%`date '+%m-%d-%Y-%k-%M-%S'`,%" > $LOGDIR/systemStats`date '+%m-%d-%Y'`.TestDBQuery.out
    fi

    sleep $TIMEOUT
done

