CPU Load Monitor Script

-------------------------------Main Program-------------------------------


Monitoring Script:
[root@config ~]# cd asptools/
[root@config asptools]# cat CPU-Monitor.sh

#!/bin/sh
#Author:zhai_kang,20131010
Dest_Path=/var/log/Monitor
######################################################CPU Monitor######################################################
#Check the log directory exists and create
if [[ ! -d $Dest_Path ]]
then
        mkdir -p $Dest_Path
fi
#Log title
if [[ $(date +%H%M) == "0000" ]]
then
        echo -e "yyyymmdd-H:M:S\t\tavg_01\t\tavg_05\t\tavg_15" > $Dest_Path/CPU-Monitor-$(date +%Y%m%d).log
fi
#Monitoring Data
uptime | awk -F "[:]" '{print $NF}' | awk -F "[,]" '{print  strftime("%Y%m%d-%T",systime()) "\t"  $1 "\t\t" $2 "\t\t" $3}' >> $Dest_Path/CPU-Monitor-$(date +%Y%m%d).log
exit



Cron job:
[root@config asptools]# crontab -l

*/1 00,8-16 * * *     /root/asptools/CPU-Monitor.sh >> ~/asptools/log/cpu.log 2>&1



See the log:
[root@config asptools]# ll log/
total 0
-rw-r--r-- 1 root root 0 Oct 10 17:59 cpu.log


[root@config asptools]# cat /var/log/Monitor/CPU-Monitor-20131011.log
101024620.jpg





-------------------------------Syslog Server-------------------------------


Find the directory where the configuration file:
[root@config asptools]# cat /etc/logrotate.conf | grep -B 1 include

# RPM packages drop log rotation information into this directory
include     /etc/logrotate.d



Custom configuration file:
[root@config asptools]# cat /etc/logrotate.d/Monitor

/var/log/Monitor/*.log {
        compress
        notifempty
        rotate     4
        create     0400 root root
        olddir     /var/log/Monitor/old/
        sharedscripts
        weekly
}

Create a log backup directory:
[root@config asptools]# mkdir /var/log/Monitor/old


Manual testing:
[root@config asptools]# logrotate -f /etc/logrotate.d/Monitor



---------------------------------------------------------------------


For more information refer to:man logrotate





你可能感兴趣的:(cpu,Monitor,load)