主页 > 知识库 > 获取磁盘IO与系统负载Load的shell脚本

获取磁盘IO与系统负载Load的shell脚本

热门标签:百度地图标注错了有责任吗 客服外呼系统怎么样 江苏云电销机器人公司 如果做线上地图标注 揭阳智能电话机器人推荐 打电话机器人接我是他的秘书 地图标注员都是年轻人 华锋e路航港口地图标注 河南信誉好的不封卡电话外呼系统

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

您可能感兴趣的文章:
  • shell脚本快速创建、格式化、挂载新添加的磁盘实现方法详解
  • powershell远程管理服务器磁盘空间的实现代码
  • 一天一个shell命令 linux好管家--磁盘--df命令详解
  • Powershell中获取所有磁盘盘符的方法
  • 使用shell脚本采集系统cpu、内存、磁盘、网络等信息
  • 监视磁盘使用情况的Shell脚本(本地+远程)
  • shell脚本快速创建格式化磁盘与详细操作步骤

标签:金昌 赤峰 娄底 邵阳 许昌 巴彦淖尔 淘宝邀评 马鞍山

巨人网络通讯声明:本文标题《获取磁盘IO与系统负载Load的shell脚本》,本文关键词  获取,磁盘,与,系统,负载,;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 下面列出与本文章《获取磁盘IO与系统负载Load的shell脚本》相关的同类信息!
  • 本页收集关于获取磁盘IO与系统负载Load的shell脚本的相关信息资讯供网民参考!
  • 推荐文章