Chinaunix首页 | 论坛 | 博客
  • 博客访问: 310147
  • 博文数量: 42
  • 博客积分: 2718
  • 博客等级: 少校
  • 技术积分: 467
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-19 10:23
个人简介

青 田 酒 店 服 务 小 姐 价 格 186-6531-7773

文章分类

全部博文(42)

文章存档

2011年(36)

2010年(6)

分类: LINUX

2010-11-04 14:25:41

响应管理员号召,写博客

#############sys_monitor.sh --by cme@2010-11-03
#!/bin/sh
eth="eth0 eth1 "
function new_df()
{
 s="";
 c=0
 ss=`df | awk 'BEGIN{total=0;avl=0;used=0;}NR > 1{print$0}'`
 for ite in $ss
 do
  s="$s $ite"
  c=`expr $c + 1`
  if [ $c -eq 6 ]
  then
   echo $s
   s=""
   c=`expr 0`
  fi
done
}
function get_eth_info()
{
 name=$1
 cat /proc/net/dev | awk -F ':' '{if(NR>2)print $1" "$2}' | awk '{print$1" "$2" "$3" "$10" "$11}' | while \
 read line
 do
# echo $line
 data=`echo $name" "$line | awk '{if($1==$2)print $3" "$4" "$5" "$6}'`
 if ! [ -z "$data" ]
 then
  echo $data
 fi
 done
}
function sum_eth()
{
 rm -fr tmp_flow.txt
 for name in $eth
 do
  ret=`get_eth_info $name`
  #echo $ret | awk '{bps+=$0;pps+$1;dps+=$2;print bps" "pps" "dps}'
  echo $ret >> tmp_flow.txt
 done
 cat tmp_flow.txt | awk 'BEGIN{rbps=0;rpps=0;tbps=0;tpps=0}{rbps+=$1;rpps+=$2;tbps+=$3;tpps+=$4}END{print rbps" "rpps" "tbps" "tpps}'
}
flow=`sum_eth`
new_df>df.txt
disk=`cat df.txt | awk 'BEGIN{total=0;avl=0;used=0;}NR > 1{total+=$2;used+=$3;avl+=$4;}END{printf"%d", avl/total*100}'`
#top -b -n 1 | grep -w Mem | awk '{print"tot_mem: "$2" used_mem: " $4 " free_mem: "$6" left:"$6/$2"%"}'
mem=`top -b -n 1 | grep -w Mem | awk '{printf"%d",$6/$2*100}'`
 #top -b -n 1 | grep -w Cpu | awk '{print"cpu: "$5}' | awk -F '%' {print$1}
 systype=`lsb_release -a | grep Desc | awk '{print $2}'`
 if [ $systype = "Red" ]
 then
 cpu=`top -b -n 1 | grep -w Cpu | awk '{print$5}' | awk -F '%' '{printf"%d",$1}'`
 else
 cpu=`top -b -n 1 | grep -w Cpu | awk '{print$8}' | awk -F '%' '{print$1}'`
 fi

 tm=`date +%s`
 if ! [ -f "flow.txt" ]
 then
 echo $tm" "$flow >flow.txt
 sleep 1
 tm=`date +%s`
 flow=`sum_eth`
 fi
 old_flow=`cat flow.txt`
 new_flow=`echo $tm $flow`
 echo $new_flow >flow.txt
 final_flow=`echo $old_flow $new_flow | awk '{dif_tm=$6-$1;dif_rbyte=$7-$2;dif_rpkt=$8-$3;dif_tbyte=$9-$4;dif_tpkt=$10-$5;printf"%d %d %d %d", dif_rbyte*8/dif_tm, dif_rpkt/dif_tm, dif_tbyte/dif_tm,dif_tpkt/dif_tm}'`
 #final_flow=`echo $old_flow $new_flow | awk '{print$0}'`
 #echo "cpu "$cpu
 printf "cpu\t%d\n" $cpu
 printf "disk\t%d\n" $disk
 printf "mem\t%s\n" $mem
 printf "nic\t"
 echo $final_flow


阅读(2708) | 评论(5) | 转发(1) |
给主人留下些什么吧!~~

duanjigang2011-05-18 12:31:37

chinaunix网友: 输出cpu        89disk        76mem        83nic        203024 20 801 4.....
嗯,这个是百分比

chinaunix网友2010-11-09 14:08:02

此人忒猥琐,鉴定完毕!

chinaunix网友2010-11-04 15:18:14

注释一下呗!!!!!

chinaunix网友2010-11-04 15:08:34

猥琐男!

chinaunix网友2010-11-04 14:28:16

输出 cpu 89 disk 76 mem 83 nic 203024 20 801 4