天道酬勤,自强不息cmesoft.blog.chinaunix.net
duanjigang
青 田 酒 店 服 务 小 姐 价 格 186-6531-7773
全部博文(42)
开发历程(3)
闲云野鹤(0)
功能畅想(2)
缺陷跟踪(3)
思考(5)
c/c++(8)
php(1)
脚本(9)
2011年(36)
2010年(6)
wangspac
L丶ventr
tjpm
liumyong
lry1945
xiaoju19
暗夜linu
sawutr
axlrose
wb123456
dafuzi
kacy16
白丁布衣
小渡2011
smile_zc
cheng_la
马丁的mo
奔跑着的
分类: LINUX
2010-11-04 14:25:41
响应管理员号召,写博客
#############sys_monitor.sh --by cme@2010-11-03#!/bin/sheth="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` fidone}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.txtdisk=`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
上一篇:处理大量数据的一种异步方法--空间换时间
下一篇:DNS查询包与响应包的构造实践
duanjigang2011-05-18 12:31:37
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
登录 注册