Chinaunix首页 | 论坛 | 博客
  • 博客访问: 507034
  • 博文数量: 173
  • 博客积分: 4112
  • 博客等级: 上校
  • 技术积分: 1577
  • 用 户 组: 普通用户
  • 注册时间: 2010-02-26 10:12
文章分类

全部博文(173)

文章存档

2012年(1)

2010年(172)

我的朋友

分类:

2010-02-26 10:27:57

[root@nagiosbak sarlog]# cat /monitor/nagios/shell/sarlog/scan_sarlog.sh
#!/bin/sh
PDIR=/monitor/nagios/shell/sarlog
runday=$(date +%Y-%m-%d)
TmpDir=/monitor/nagios/tmp
for i in `/bin/cat /monitor/nagios/shell/sarlog/machine.lst`
do
   /usr/bin/scp ${PDIR}/sarlog.sh ${i}:/root && /usr/bin/rsh ${i} /root/sarlog.sh &
done
 
[root@nagiosbak sarlog]# cat sarlog.sh
#!/bin/sh
host=$(hostname)
channel=$(hostname | sed 's/[0-9]//g')
runday=$(date +%Y-%m-%d)
IPhost=$(/sbin/ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}')

/usr/bin/sar -u 60 120 >  /tmp/$(hostname)-${runday}.txt
/bin/sed '/ \+/s//,/g'  /tmp/$(hostname)-${runday}.txt |  /bin/sed -n '4,$p'  | grep -v Average  |awk -F "," '{print "'"$host"'"",""'"$channel"'"",""'"$IPhost"'"",""'"$runday"'"" "$1","$4","$6","$7","$9}'  > /tmp/$(hostname)${runday}.txt
rm -rf /tmp/$(hostname)-${runday}.txt
 
 
[root@nagiosbak sarlog]# cat /monitor/nagios/shell/sarlog/process_sarlog.sh
#!/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}.txt ${TmpDir}
done
/bin/cat ${TmpDir}/*${runday}.txt >> ${TmpDir}/Tmp${runday}.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}Result.txt
        let count=count+1
done
rm -rf ${TmpDir}/*${runday}.txt
/usr/local/mysql/bin/mysql -u root -D nagios -pbj7n48dM  <   load data infile '${TmpDir}/${runday}Result.txt' into table t_daily_stats FIELDS TERMINATED BY  ',';
EOF
阅读(1148) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~