Solaris 监控网卡流量

2543阅读 0评论2010-04-01 skybin090804
分类:

文件: 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.

我们可以看到每次运行这个命令的第一行结果是开机以来的总数。
上一篇:自我书写的一些监控Solaris服务器主机的脚本
下一篇:批量检测域名