当前位置: 操作系统/服务器>linux
获取磁盘IO与系统负载Load的shell脚本
来源: 互联网 发布时间:2014-10-14
本文导语: 1,提取系统负载信息 代码如下:#!/bin/shhost=$(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}')i=1 while [ $i -le 120 ];do rundaytime=$(date "+%Y-%m-%d %H:%M:%S...
1,提取系统负载信息
代码如下:
#!/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}')
i=1
while [ $i -le 120 ];do
rundaytime=$(date "+%Y-%m-%d %H:%M:%S")
/bin/cat /proc/loadavg | awk -F " " '{print "'"$rundaytime"'"","$1","$2","$3","$4","$5}' >> /tmp/$(hostname)-${runday}load.txt
/usr/bin/sar -u 1 1 | grep -v Average | /bin/sed -n '4,$p' | awk -F " " '{print "'"$rundaytime"'"","$4","$6","$7","$9}' >> /tmp/$(hostname)-${runday}sar.txt
i=$((i+1))
sleep 59
done
awk -F "," '{print "'"$host"'"",""'"$channel"'"",""'"$IPhost"'"","$1","$2","$3","$4","$5}' /tmp/$(hostname)-${runday}sar.txt > /tmp/$(hostname)${runday}sar.txt
awk -F "," '{print "'"$host"'"",""'"$channel"'"",""'"$IPhost"'"","$1","$2","$3","$4","$5","$6}' /tmp/$(hostname)-${runday}load.txt > /tmp/$(hostname)${runday}load.txt
rm -rf /tmp/$(hostname)-${runday}sar.txt
rm -rf /tmp/$(hostname)-${runday}load.txt
2,代码2
代码如下:
#!/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
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