linux os 監控

aishu521發表於2013-05-15

##################os cpu mem disk ##############
51 23 * * * df -h >/home/oraprod/sys/disk
51 23 * * * free -m >/home/oraprod/sys/mem
0 9 * * * iostat -xt 300 144 > /home/oraprod/sys/cpudiskam
0 21 * * * iostat -xt 300 144 > /home/oraprod/sys/cpudiskpm
52 23 * * * sh /home/oraprod/check.sh
15 21 * * * sh /home/oraprod/checkcpuam.sh
15 9 * * * sh /home/oraprod/checkcpupm.sh

disk mem監控
[oraprod@ebsdb ~]$ cat /home/oraprod/check.sh
rm -rf /home/oraprod/sys/disk_* /home/oraprod/sys/mem_* /home/oraprod/sys/cpu_* /home/oraprod/sys/disk.sql /home/oraprod/sys/mem.sql /home/oraprod/sys/cpu.sql
cat /home/oraprod/sys/disk|grep -v r|awk '{print $1}' >/home/oraprod/sys/disk1
cat /home/oraprod/sys/disk|grep -v r|awk '{print $2}' >/home/oraprod/sys/disk2
cat /home/oraprod/sys/disk|grep -v r|awk '{print $3}' >/home/oraprod/sys/disk3
cat /home/oraprod/sys/disk|grep -v r|awk '{print $4}' >/home/oraprod/sys/disk4
cat /home/oraprod/sys/disk|grep -v r|awk '{print $5}' >/home/oraprod/sys/disk5
cat /home/oraprod/sys/disk|grep -v r|awk '{print $6}' >/home/oraprod/sys/disk6
cat /home/oraprod/sys/disk2|sed s/^/,\'\/g>/home/oraprod/sys/disk_2
cat /home/oraprod/sys/disk3|sed s/^/,\'\/g>/home/oraprod/sys/disk_3
cat /home/oraprod/sys/disk4|sed s/^/,\'\/g>/home/oraprod/sys/disk_4
cat /home/oraprod/sys/disk5|sed s/^/,\'\/g>/home/oraprod/sys/disk_5
cat /home/oraprod/sys/disk6|sed s/^/,\'\/g>/home/oraprod/sys/disk_6
cat /home/oraprod/sys/disk_2|sed s/$/\'\/g>/home/oraprod/sys/disk_22
cat /home/oraprod/sys/disk_3|sed s/$/\'\/g>/home/oraprod/sys/disk_33
cat /home/oraprod/sys/disk_4|sed s/$/\'\/g>/home/oraprod/sys/disk_44
cat /home/oraprod/sys/disk_5|sed s/$/\'\/g>/home/oraprod/sys/disk_55
cat /home/oraprod/sys/disk_6|sed s/$/\'\/g>/home/oraprod/sys/disk_66
cat /home/oraprod/sys/disk1|sed s/^/insert\ into\ checkdisk\ values\(\'192\.168\.0\.6\',\'/g>/home/oraprod/sys/disk_1
cat /home/oraprod/sys/disk_1|sed s/$/\'\/g>/home/oraprod/sys/disk_11
paste /home/oraprod/sys/disk_11 /home/oraprod/sys/disk_22 >/home/oraprod/sys/disk_21
paste /home/oraprod/sys/disk_21 /home/oraprod/sys/disk_33 >/home/oraprod/sys/disk_31
paste /home/oraprod/sys/disk_31 /home/oraprod/sys/disk_44 >/home/oraprod/sys/disk_41
paste /home/oraprod/sys/disk_41 /home/oraprod/sys/disk_55 >/home/oraprod/sys/disk_51
paste /home/oraprod/sys/disk_51 /home/oraprod/sys/disk_66 >/home/oraprod/sys/disk_61
cat /home/oraprod/sys/disk_61|sed s/$/\)\;/g >>/home/oraprod/sys/disk.sql
cat /home/oraprod/sys/mem|grep -v r|awk '{print $1}' >/home/oraprod/sys/mem1
cat /home/oraprod/sys/mem|grep -v r|awk '{print $2}' >/home/oraprod/sys/mem2
cat /home/oraprod/sys/mem|grep -v r|awk '{print $3}' >/home/oraprod/sys/mem3
cat /home/oraprod/sys/mem|grep -v r|awk '{print $4}' >/home/oraprod/sys/mem4
cat /home/oraprod/sys/mem2|sed s/^/,\/g>/home/oraprod/sys/mem_22
cat /home/oraprod/sys/mem3|sed s/^/,\/g>/home/oraprod/sys/mem_33
cat /home/oraprod/sys/mem4|sed s/^/,\/g>/home/oraprod/sys/mem_44
cat /home/oraprod/sys/mem1|sed s/^/insert\ into\ checkmem\ values\(\'192\.168\.0\.6\',\'/g>/home/oraprod/sys/mem_1
cat /home/oraprod/sys/mem_1|sed s/$/\'\/g>/home/oraprod/sys/mem_11
paste /home/oraprod/sys/mem_11 /home/oraprod/sys/mem_22 >/home/oraprod/sys/mem_21
paste /home/oraprod/sys/mem_21 /home/oraprod/sys/mem_33 >/home/oraprod/sys/mem_31
paste /home/oraprod/sys/mem_31 /home/oraprod/sys/mem_44 >/home/oraprod/sys/mem_41
cat /home/oraprod/sys/mem_41|sed s/$/\)\;/g >>/home/oraprod/sys/mem.sql
#echo 'exit' >>/home/oraprod/sys/mem.sql
echo 'exit' >>/home/oraprod/sys/disk.sql
#export  ORACLE_HOME="/ebs10/oracle/oraprod/db/tech_st/11.1.0"
#$ORACLE_HOME/bin/sqlplusoscheck/checkdb@test@/home/oraprod/sys/cpu.sql
sqlplus oscheck/checkdb@checkdb <@/home/oraprod/sys/mem.sql
#sqlplus oscheck/checkdb@checkdb <@/home/oraprod/sys/disk.sql

cpu監控 分上午下午
[oraprod@ebsdb ~]$ cat  /home/oraprod/checkcpuam.sh
sysdir="/home/oraprod/sys/"
rm -rf /home/oraprod/sys/cpuam_*  /home/oraprod/sys/cpuam3 /home/oraprod/sys/cpuam4 /home/oraprod/sys/cpuam5 /home/oraprod/sys/cpuam6 /home/oraprod/sys/cpuam7  /home/oraprod/sys/cpuam.sql
cp /home/oraprod/sys/cpudiskam /home/oraprod/sys/cpudiskam.bak
i=1
cn=5
cat $sysdir/cpudiskam.bak|while read line
do
        if [ "$i" -eq "$cn" ];
        then
                echo $line|awk '{print $1}' >>$sysdir/cpuam3
                echo $line|awk '{print $2}' >>$sysdir/cpuam4
                echo $line|awk '{print $3}' >>$sysdir/cpuam5
                echo $line|awk '{print $4}' >>$sysdir/cpuam6
                echo $line|awk '{print $6}' >>$sysdir/cpuam7
                cn=$(($cn + 16))
        fi
     i=$(($i+1))
done
cat /home/oraprod/sys/cpuam3|sed s/^/,\/g>/home/oraprod/sys/cpuam_33
cat /home/oraprod/sys/cpuam4|sed s/^/,\/g>/home/oraprod/sys/cpuam_44
cat /home/oraprod/sys/cpuam5|sed s/^/,\/g>/home/oraprod/sys/cpuam_55
cat /home/oraprod/sys/cpuam6|sed s/^/,\/g>/home/oraprod/sys/cpuam_66
cat /home/oraprod/sys/cpuam7|sed s/^/,\/g>/home/oraprod/sys/cpuam_77
cat /home/oraprod/sys/tam|sed s/^/insert\ into\ checkcpu\ values\(\'192\.168\.0\.25\',\/g>/home/oraprod/sys/cpuam_11

### cat /home/oraprod/sys/cpudiskam 需要空的144行
cat /home/oraprod/sys/cpudiskam|grep Time|awk '{print $2}'|sed s/^/\'/g|sed s/$/\'/g >/home/oraprod/sys/cpuam_time
paste /home/oraprod/sys/cpuam_11 /home/oraprod/sys/cpuam_time > /home/oraprod/sys/cpuam_time_21
paste /home/oraprod/sys/cpuam_11 /home/oraprod/sys/cpuam_33 >/home/oraprod/sys/cpuam_31
paste /home/oraprod/sys/cpuam_31 /home/oraprod/sys/cpuam_44 >/home/oraprod/sys/cpuam_41
paste /home/oraprod/sys/cpuam_41 /home/oraprod/sys/cpuam_55 >/home/oraprod/sys/cpuam_51
paste /home/oraprod/sys/cpuam_51 /home/oraprod/sys/cpuam_66 >/home/oraprod/sys/cpuam_61
paste /home/oraprod/sys/cpuam_61 /home/oraprod/sys/cpuam_77 >/home/oraprod/sys/cpuam_71
cat /home/oraprod/sys/cpuam_71|sed s/$/\)\;/g >>/home/oraprod/sys/cpuam.sql
echo 'commit;' >>/home/oraprod/sys/cpuam.sql
echo 'exit' >>/home/oraprod/sys/cpuam.sql
#home/oraprodort ORACLE_HOME="/u01/app/oracle/product/10.2.0/"
sqlplus oscheck/checkdb@checkdb @/home/oraprod/sys/cpuam.sql
[oraprod@ebsdb ~]$ cat  /home/oraprod/checkcpupm.sh
sysdir="/home/oraprod/sys/"
rm -rf /home/oraprod/sys/cpupm_*  /home/oraprod/sys/cpupm3 /home/oraprod/sys/cpupm4 /home/oraprod/sys/cpupm5 /home/oraprod/sys/cpupm6 /home/oraprod/sys/cpupm7  /home/oraprod/sys/cpupm.sql
cp /home/oraprod/sys/cpudiskpm /home/oraprod/sys/cpudiskpm.bak
i=1
cn=5
cat $sysdir/cpudiskpm.bak|while read line
do
        if [ "$i" -eq "$cn" ];
        then
                echo $line|awk '{print $1}' >>$sysdir/cpupm3
                echo $line|awk '{print $2}' >>$sysdir/cpupm4
                echo $line|awk '{print $3}' >>$sysdir/cpupm5
                echo $line|awk '{print $4}' >>$sysdir/cpupm6
                echo $line|awk '{print $6}' >>$sysdir/cpupm7
                cn=$(($cn + 16))
        fi
     i=$(($i+1))
done
cat /home/oraprod/sys/cpupm3|sed s/^/,\/g>/home/oraprod/sys/cpupm_33
cat /home/oraprod/sys/cpupm4|sed s/^/,\/g>/home/oraprod/sys/cpupm_44
cat /home/oraprod/sys/cpupm5|sed s/^/,\/g>/home/oraprod/sys/cpupm_55
cat /home/oraprod/sys/cpupm6|sed s/^/,\/g>/home/oraprod/sys/cpupm_66
cat /home/oraprod/sys/cpupm7|sed s/^/,\/g>/home/oraprod/sys/cpupm_77
cat /home/oraprod/sys/tpm|sed s/^/insert\ into\ checkcpu\ values\(\'192\.168\.0\.25\',\/g>/home/oraprod/sys/cpupm_11
cat /home/oraprod/sys/cpudiskpm|grep Time|awk '{print $2}'|sed s/^/\'/g|sed s/$/\'/g >/home/oraprod/sys/cpupm_time
paste /home/oraprod/sys/cpupm_11 /home/oraprod/sys/cpupm_time > /home/oraprod/sys/cpupm_time_21
paste /home/oraprod/sys/cpupm_time_21 /home/oraprod/sys/cpupm_33 >/home/oraprod/sys/cpupm_31
paste /home/oraprod/sys/cpupm_31 /home/oraprod/sys/cpupm_44 >/home/oraprod/sys/cpupm_41
paste /home/oraprod/sys/cpupm_41 /home/oraprod/sys/cpupm_55 >/home/oraprod/sys/cpupm_51
paste /home/oraprod/sys/cpupm_51 /home/oraprod/sys/cpupm_66 >/home/oraprod/sys/cpupm_61
paste /home/oraprod/sys/cpupm_61 /home/oraprod/sys/cpupm_77 >/home/oraprod/sys/cpupm_71
cat /home/oraprod/sys/cpupm_71|sed s/$/\)\;/g >>/home/oraprod/sys/cpupm.sql
echo 'commit;' >>/home/oraprod/sys/cpupm.sql
echo 'exit' >>/home/oraprod/sys/cpupm.sql
#home/oraprodort ORACLE_HOME="/u01/app/oracle/product/10.2.0/"
sqlplus oscheck/checkdb@checkdb @/home/oraprod/sys/cpupm.sql

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15187685/viewspace-761130/,如需轉載,請註明出處,否則將追究法律責任。

相關文章