1,提取系統負載信息
復制代碼 代碼如下:2,代碼2
復制代碼 代碼如下:3,代碼3
復制代碼 代碼如下:
#!/bin/sh
PDIR=/monitor/nagios/shell/sarlog
runday=$(date +%Y-%m-%d)
TmpDir=/monitor/nagios/shell/sarlog/log
Machinelst=/monitor/nagios/shell/sarlog/machine.lst
for i in `/bin/cat /monitor/nagios/shell/sarlog/machine.lst`
do
/usr/bin/scp ${i}:/tmp/*${runday}sar.txt ${TmpDir}
/usr/bin/scp ${i}:/tmp/*${runday}load.txt ${TmpDir}
done
/bin/cat ${TmpDir}/*${runday}sar.txt >> ${TmpDir}/Tmp${runday}.txt
/bin/cat ${TmpDir}/*${runday}load.txt >> ${TmpDir}/${runday}loadResult.txt
count=1
Line=$(cat ${TmpDir}/Tmp${runday}.txt |wc -l)
>${TmpDir}/Result${runday}.txt
while [ "$count" -le "$Line" ]
do
Idle=$(sed -n "${count}p" ${TmpDir}/Tmp${runday}.txt | awk -F "," '{print $8}')
Busy=`echo "scale=2;100-$Idle"|bc`
sed -n "${count}p" ${TmpDir}/Tmp${runday}.txt | sed "s/$/,$Busy/g" >> ${TmpDir}/${runday}sarResult.txt
let count=count+1
done
/usr/local/mysql/bin/mysql -u root -D nagios -pbj7n48dM <<EOF
load data infile '${TmpDir}/${runday}sarResult.txt' into table t_daily_stats FIELDS TERMINATED BY ',';
load data infile '${TmpDir}/${runday}loadResult.txt' into table t_daily_load FIELDS TERMINATED BY ',';
EOF
rm -rf ${TmpDir}/*${runday}sar.txt
rm -rf ${TmpDir}/*${runday}load.txt
rm -rf rm -rf ${TmpDir}/*${runday}.txt