Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System Monitoring Script (KSH)

Status
Not open for further replies.

ponetguy2

MIS
Aug 28, 2002
442
US
Here is a usefull monitoring script. Please make sure you have sufficient disk space before running this script. One can also edit the time interval per command within the script.

Enjoy,




#System Resource Monitoring Script
##################################################################################################################
#To help you easily gather various system resource usage statistics, you can use the following script.
#This script runs commands such as vmstat, iostat, netstat and so on over a specified interval.
#It places a copy of the output in the /tmp directory, where you can examine system resource usage
#statistics in a centralized location. Since this is a simple Korn shell script, you can easily
#modify the script to suit your needs. For example, you can change the interval the script
#uses to sample system activity, the location of the output directory, and more.
#To use this script:
#
#Copy the contents inside the lines to the file name of your choice (for example, sys_mon.ksh).
#Make the file executable using the chmod command:
#% chmod u+x sys_mon.ksh
#Run the script:
#% sys_mon.ksh
#Note - This script is provided as a courtesy. Usage, support and modifications are left solely up to the user.
###################################################################################################################





!/bin/ksh


LOGDIR="/tmp/test"
mkdir $LOGDIR

NETSTAT_OUTFILE="$LOGDIR/netstat.out"
MPSTAT_OUTFILE="$LOGDIR/mpstat.out"
VMSTAT_OUTFILE="$LOGDIR/vmstat.out"
IOSTAT_OUTFILE="$LOGDIR/iostat.out"
PS_OUTFILE="$LOGDIR/ps_aux.out"
INTERVAL=5
COUNT=10
TIME=`expr $INTERVAL \* $COUNT`
TIMEPLUS=`expr $TIME + 5`
X=1


while [ $X != 200 ]
do

echo "" >> $PS_OUTFILE
date >> $PS_OUTFILE
/usr/ucb/ps -aux >> $PS_OUTFILE &

echo "" >> $MPSTAT_OUTFILE
date >> $MPSTAT_OUTFILE
mpstat $INTERVAL $COUNT >> $MPSTAT_OUTFILE &
MPSTATPID=$!

echo "" >> $VMSTAT_OUTFILE
date >> $VMSTAT_OUTFILE
vmstat $INTERVAL $COUNT >> $VMSTAT_OUTFILE &
VMSTATPID=$!

echo "" >> $IOSTAT_OUTFILE
date >> $IOSTAT_OUTFILE
iostat -xp $INTERVAL $COUNT >> $IOSTAT_OUTFILE &
IOSTATPID=$!

echo "">> $NETSTAT_OUTFILE
date >> $NETSTAT_OUTFILE
netstat -i $INTERVAL >> $NETSTAT_OUTFILE &
NETSTATPID=$!

echo "mpstat $MPSTATPID"
echo "vmstat $VMSTATPID"
echo "iostat $IOSTATPID"
echo "netstat $NETSTATPID"

echo "sleeping for $TIMEPLUS"
sleep $TIMEPLUS

echo "sleeping done"

kill -9 $NETSTATPID

X=`expr $X + 1`
done

Carlo Reyes

Technology/Systems - Delivery
Networks and Infrastructure

Chicago Customer Technical Support
 
Thank you very much for the script and it is very usefull to many admins, here my case is diffrent as i don't know of networks though iam consider as sys admin.
i would appreciate it if you can give me more details of what the out shows and how to analysis it.

Thanks in advance.

Bonagiri
pbonagir@in.ibm.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top