Chinaunix首页 | 论坛 | 博客
  • 博客访问: 812894
  • 博文数量: 167
  • 博客积分: 7173
  • 博客等级: 少将
  • 技术积分: 1671
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-04 23:07
文章分类

全部博文(167)

文章存档

2018年(1)

2017年(11)

2012年(2)

2011年(27)

2010年(88)

2009年(38)

分类:

2010-04-01 18:14:24

文件: nicstat.zip
大小: 4KB
下载: 下载
在上一篇文章中提到了自我书写的监控Solaris的一套脚本,在使用过程发现了一个以前自己也没注意到的问题:
netstat -in  输出的是每秒包发送接受的大小;我想了一下solaris上没有监控流量的命令啊;
上网找一下发现有一个perl的脚本能监控流量,运行的情况如下
root@sunha7 # nicstat 1 2
    Time     Int   rKB/s   wKB/s   rPk/s   wPk/s    rAvs    wAvs   %Util    Sat
17:58:27     ce0    5.43    0.35   19.51    3.33   285.1   108.8    0.00   0.00
17:58:27     ce1    0.00    0.00    0.00    0.00    0.00    0.00    0.00   0.00
17:58:27     ge0    0.00    0.00    0.00    0.00    0.00    0.00    0.00   0.00
17:58:27    eri0    0.00    0.00    0.00    0.00    0.00    0.00    0.00   0.00
17:58:27     ce2    0.00    0.00    0.00    0.00    0.00    0.00    0.00   0.00
17:58:27     ce3    0.00    0.00    0.00    0.00    0.00    0.00    0.00   0.00
17:58:27     lo0    0.00    0.00    6.62    6.62    0.00    0.00    0.00   0.00
    Time     Int   rKB/s   wKB/s   rPk/s   wPk/s    rAvs    wAvs   %Util    Sat
17:58:28     ce0    2.21    4.00   35.76   31.79   63.17   129.0    0.01   0.00
17:58:28     ce1    0.00    0.00    0.00    0.00    0.00    0.00    0.00   0.00
17:58:28     ge0    0.00    0.00    0.00    0.00    0.00    0.00    0.00   0.00
17:58:28    eri0    0.00    0.00    0.00    0.00    0.00    0.00    0.00   0.00
17:58:28     ce2    0.00    0.00    0.00    0.00    0.00    0.00    0.00   0.00
17:58:28     ce3    0.00    0.00    0.00    0.00    0.00    0.00    0.00   0.00
17:58:28     lo0    0.00    0.00    0.99    0.99    0.00    0.00    0.00   0.00

所以脚本改写如下
icstat 1 6 | grep -v Time > net_tmp.log
ifconfig -a | grep "UP" | grep -v "lo0" | awk -F: '{print $1}' | while read line
do
    grep $line net_tmp.log | tail -5 | awk 'BEGIN{sum=0}{sum+=$3} END{printf ("soltrafficin_%s=%.2f\n",interface,sum*8/5)}' i
nterface=$line net_tmp.log
    grep $line net_tmp.log | tail -5 | awk 'BEGIN{sum=0}{sum+=$4} END{printf ("soltrafficout_%s=%.2f\n",interface,sum*8/5)}'
interface=$line net_tmp.log
done

rm -f net_tmp.log


注意这个nicstat 里面注释的一句话:

This prints out the KB/s transferred for all the network cards (NICs),
# including packet counts and average sizes. The first line is the summary
# data since boot.

我们可以看到每次运行这个命令的第一行结果是开机以来的总数。
阅读(2420) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~