主頁 > 知識庫 > 獲取磁盤IO與系統(tǒng)負載Load的shell腳本

獲取磁盤IO與系統(tǒng)負載Load的shell腳本

熱門標簽:網(wǎng)站排名優(yōu)化 AI電銷 鐵路電話系統(tǒng) 百度競價排名 地方門戶網(wǎng)站 呼叫中心市場需求 服務外包 Linux服務器

1,提取系統(tǒng)負載信息

復制代碼 代碼如下:

#!/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

您可能感興趣的文章:
  • shell腳本快速創(chuàng)建、格式化、掛載新添加的磁盤實現(xiàn)方法詳解
  • powershell遠程管理服務器磁盤空間的實現(xiàn)代碼
  • 一天一個shell命令 linux好管家--磁盤--df命令詳解
  • Powershell中獲取所有磁盤盤符的方法
  • 使用shell腳本采集系統(tǒng)cpu、內存、磁盤、網(wǎng)絡等信息
  • 監(jiān)視磁盤使用情況的Shell腳本(本地+遠程)
  • shell腳本快速創(chuàng)建格式化磁盤與詳細操作步驟

標簽:湖南 黃山 蘭州 衡水 崇左 湘潭 仙桃 銅川

巨人網(wǎng)絡通訊聲明:本文標題《獲取磁盤IO與系統(tǒng)負載Load的shell腳本》,本文關鍵詞  ;如發(fā)現(xiàn)本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266