擷取磁碟IO與系統負載Load的shell指令碼

來源:互聯網
上載者:User
本節介紹的幾段shell指令碼,可以用於提取磁碟的I/O資訊,系統負載Load資訊等 

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  <<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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.