Running NMON on the VIO Server
#!/usr/bin/ksh
#
################################################################
# Program : start_nmon.ksh
# Author : Stephen Diwell
# Date : 4th November 2009
# Desc : This script is run from roots cron once at 0000
# and from /etc/rc.d/rc2.d at system reboot time.
# This script starts the /usr/bin/topas_nmon process.
################################################################
#
# Tunable Variables
#
nmon_exe=/usr/bin/topas_nmon # nmon executable
[[ ! -f ${nmon_exe} ]] && nmon_exe=/usr/local/bin/nmon
nmon_sleep_seconds=300 # sleep time between nmon iterations
nmon_stats_count=288 # number or nmon iterations
nmon_file_mask=nmon # output filename mask
# Flags for topas_nmon are:
# d for disk service times
# N for NFS stats
# ^ for adapter stats
# O for SEA adapter stats - VIO Server only
if lsdev -Cc adapter | grep -q "Shared Ethernet Adapter"
then
FLAGS="-d -N -^ -O" # VIO Server
nmon_monitor_dir=/home/padmin/nmon # Output directory - VIO Server
else
##FLAGS="-d -N -^ -Y" # AIX Server - With summary tab
FLAGS="-d -N -^" # AIX Server - Without summary tab
nmon_monitor_dir=/usr/local/nmon # Output directory - AIX Server
fi
[[ ! -d ${nmon_monitor_dir} ]] && mkdir -p -m 775 ${nmon_monitor_dir}
#
# Functions
#
format_number()
{
#
# returns number passed with leading zeros padded to length
#
number=$1
length=$2
echo $number | awk '{ printf "%0'${length}'d",$1 }'
}
#
# Main
#
hostname=$( hostname )
todays_date=$( date +%d%m%Y )
#
# Figure out the nmon output file name - Allow for nmon restarts
#
count=1
out_file=${nmon_monitor_dir}/${nmon_file_mask}_${hostname}_${todays_date}_$(format_number ${count} 2).csv
while [[ -s ${out_file} || -s ${out_file}.Z ]]
do
(( count = count + 1 ))
out_file=${nmon_monitor_dir}/${nmon_file_mask}_${hostname}_${todays_date}_$(format_number ${count} 2).csv
done
#
# Run nmon
#
print "Writing nmon output to $out_file"
cmd="${nmon_exe} -F ${out_file} ${FLAGS} -s ${nmon_sleep_seconds} -c ${nmon_stats_count}"
#
# Stop any existing nmons writing to monitor
#
ps -ef | \
grep "${nmon_monitor_dir}/${nmon_file_mask}_" | \
grep -v grep | \
awk '{ print $2 }' | \
xargs -i kill -15 {}
#
# start up nmon
#
eval ${cmd}
sleep 10
chmod 644 $out_file
#
# Compress previous nmon data files.
#
print "Compressing previous nmon data files."
sleep 10
for FILE in $( ls -1 ${nmon_monitor_dir}/${nmon_file_mask}_*csv | grep -v ${out_file} )
do
compress ${FILE}
done
#
# Housekeeping - Keep 30 days.
#
find ${nmon_monitor_dir} -name ${nmon_file_mask}_\* -mtime +30 -exec rm {} \;
exit 0