Hi
Currently we have nmon running on our Red hat Linux server.
The ouput file is now coming with the naming convention as "servername_160321_0010.nmon".
The output file naming convention has to be changed as "nmon_servername_daily_2016.03.21_00.00.00"
How can we do it ? Any suggestions please ?
Below is the nmon script scheduled in cron.
[root@servername nmonlog]# crontab -l | grep -i nmon
10 00 * * * /usr/bin/nmon_x86 -ft -s 60 -c 1440 -m /vol/nmonlog > /dev/null 2>&1
Below is the location where the output files are saved :
[root@servername nmonlog]# pwd
/vol/nmonlog
[root@servername nmonlog]# ls -ltr | grep -i nmon
-rw-r--r-- 1 root root 3820143 Mar 11 00:09 servername_160310_0010.nmon
---------- Post updated at 02:15 AM ---------- Previous update was at 02:08 AM ----------
Below is the script info :
[root@servername nmonlog]# crontab -l | grep -i /vol/nmonlog/Unix_Stat
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /vol/nmonlog/Unix_Statistics.sh >/dev/null 2>&1 #CPU,Memory & Filesystem Monitoring
[root@servername nmonlog]# cat /vol/nmonlog/Unix_Statistics.sh
#! /bin/bash
# Include the Email Ids here
email=abcde@hotmail.com
# Capacity Monitor : Set the thersholds here
cpu_thres=80
swap_thres=60
mem_thres=87
fs_thers=86
# Enter the file system name here to exclude from FS Capacity Monitoring
# Example : fs_exclude="tmp|usr|oracle"
fs_exclude="nfs|tmpfs|cifs"
# Monitoring script output
cpu_op="/vol/cpumonitor"
swap_op="/vol/swapmonitor"
mem_op="/vol/memmonitor"
fs_mon="/vol/fsmonitor"
# *********************************CPU Monitoring script************************************
cpu_usage=$(top -b -n 1 | awk -F'[:,]' '/^Cpu/{sub("\\..*","",$2); print $2}')
if [ $cpu_usage -ge $cpu_thres ]
then
echo -e "<html>" > $cpu_op
echo -e "<body> <pre>" >> $cpu_op
echo -e "<font face=\"Trebuchet MS\" >" >> $cpu_op
echo -e " ********* CPU Utilization on" `hostname` "is above thershold **********" >> $cpu_op
echo -e "\n" >> $cpu_op
echo -e " Current CPU Utilization : $cpu_usage%" >> $cpu_op
echo -e " ***********************************" >> $cpu_op
echo " Here are the top 10 Processes " >> $cpu_op
echo -e " ***********************************" >> $cpu_op
echo -e " </font>" >> $cpu_op
echo -e "\n" >> $cpu_op
echo -e "%CPU COMMAND PID EUSER \n" >> $cpu_op
ps axo pcpu,comm,pid,euser | sort -nr | grep -v "%" | head -n 10 >> $cpu_op
echo -e "\n" >> $cpu_op
echo -e " <font face=\"Trebuchet MS\" > Note : Please involve respective team.</font>" >> $cpu_op
echo -e "</pre></body>" >> $cpu_op
mail -s "$(echo -e "ERROR - CPU Utilization on" `hostname` "is above thershold\nContent-Type: text/html")" $email < $cpu_op
fi
# *********************************SWAP Monitoring script************************************
swap_usage=$(free|awk '/^Swap/ {printf "%4.0f\n",$3/$2*100}')
function swap_func(){
SUM=0
OVERALL=0
for DIR in `find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]"` ; do
PID=`echo $DIR | cut -d / -f 3`
PROGNAME=`ps -p $PID -o comm --no-headers`
for SWAP in `grep Swap $DIR/smaps 2>/dev/null| awk '{ print $2 }'`
do
let SUM=$SUM+$SWAP
done
echo "PID=$PID - Swap used: $SUM - ($PROGNAME )"
let OVERALL=$OVERALL+$SUM
SUM=0
done
}
if [ $swap_usage -ge $swap_thres ]
then
echo -e "<html>" > $swap_op
echo -e "<body> <pre>" >> $swap_op
echo -e "<font face=\"Trebuchet MS\" >" >> $swap_op
echo -e " ********* Swap Utilization on" `hostname` "is above thershold **********" >> $swap_op
echo -e "\n" >> $swap_op
echo -e " Current SWAP Utilization : $swap_usage%" >> $swap_op
echo -e " ***********************************" >> $swap_op
echo " Here are the top 10 Processes " >> $swap_op
echo -e " ***********************************" >> $swap_op
echo -e " </font>" >> $swap_op
echo -e "\n" >> $swap_op
swap_func | sort -n -k 10 | head >> $swap_op
echo -e "\n" >> $swap_op
echo -e " <font face=\"Trebuchet MS\" > Note : Please involve respective team. </font>" >> $swap_op
echo -e "</pre></body>" >> $swap_op
mail -s "$(echo -e "ERROR - SWAP Utilization on" `hostname` "is above thershold\nContent-Type: text/html")" $email < $swap_op
fi
# *********************************Memory Monitoring script************************************
mem_total=`cat /proc/meminfo | grep MemTotal: | awk '{print $2}'`
mem_used=`cat /proc/meminfo | grep Active: | awk '{print $2}'`
mem_usage=$[$mem_used * 100 / $mem_total]
if [ $mem_usage -ge $mem_thres ]
then
echo -e "<html>" > $mem_op
echo -e "<body> <pre>" >> $mem_op
echo -e "<font face=\"Trebuchet MS\" >" >> $mem_op
echo -e " ********* Memory Utilization on" `hostname` "is above thershold **********" >> $mem_op
echo -e "\n" >> $mem_op
echo -e " Current Memory Utilization : $mem_usage%" >> $mem_op
echo -e " ***********************************" >> $mem_op
echo " Here are the top 10 Processes " >> $mem_op
echo -e " ***********************************" >> $mem_op
echo -e " </font>" >> $mem_op
echo -e "\n" >> $mem_op
echo -e "%MEM COMMAND PID EUSER \n" >> $mem_op
ps axo pmem,comm,pid,euser | sort -nr | grep -v "%" | head -n 10 >> $mem_op
echo -e "\n" >> $mem_op
echo -e " <font face=\"Trebuchet MS\" > Note : Please involve respective team. </font>" >> $mem_op
echo -e "</pre></body>" >> $mem_op
mail -s "$(echo -e "ERROR - Memory Utilization on" `hostname` "is above thershold\nContent-Type: text/html")" $email < $mem_op
fi
# *********************************FS Capacity monitoring script************************************
fs_func() {
echo -e "<html>" > $fs_mon
echo -e "<body> <pre>" >> $fs_mon
echo -e "<font face=\"Trebuchet MS\" >" >> $fs_mon
echo -e " ********* File System Utilization on" `hostname` "is above thershold **********" >> $fs_mon
echo -e "\n" >> $fs_mon
echo -e " File System $fs Utilization : $fs_usage%" >> $fs_mon
echo -e " *******************************" >> $fs_mon
echo " Here are the Large Files " >> $fs_mon
echo -e " *******************************" >> $fs_mon
echo -e "\n" >> $fs_mon
echo -e "Size : Owner : File Name " >> $fs_mon
find $fs -xdev -size +10000000c -exec ls -lh {} \; | awk '{ print $5 " :" $3 " : "$9 }' | sort -nr | head >> $fs_mon
echo -e "\n" >> $fs_mon
echo -e " Note : Please involve respective team and take necessary action" >> $fs_mon
echo -e "</pre></body>" >> $fs_mon
mail -s "$(echo -e "ERROR - File System $fs Utilization on" `hostname` "is above thershold\nContent-Type: text/html")" $email < $fs_mon
sleep 5
}
for fs in ` mount | egrep -v "proc|devpts|sysfs|${fs_exclude}" | awk '{print $3}'`
do
df -h $fs | tail -1 | awk '{print $4}' | grep -i "%" > /dev/null
if [ $? -eq 0 ]
then
fs_usage=`df -h $fs | tail -1 | awk '{print $4}' | grep -i "%" | sed '$s/.$//'`
if [ $fs_usage -gt $fs_thers ]
then
fs_func
fi
else
fs_usage=`df -h $fs | tail -1 | awk '{print $5}' | grep -i "%" | sed '$s/.$//'`
if [ $fs_usage -gt $fs_thers ]
then
fs_func
fi
fi
done