监控 IPv4 与 IPv6 流量

监控 IPv4 与 IPv6 流量

我们的业务中运行着一个功能齐全的双栈网络。有没有人找到一种简单的工具来监控给定主机上的 IPv4 与 IPv6 流量比率?当我说“简单”时,我指的是类似于“vnstat”的守护进程/服务

一份完美的报告,其最简单的形式看起来应该是这样的:

                 Total     IPv4          IPv6          Ratio
This Month:      300gb     100gb (33%)   200gb (66%)   1:2
This Week:       5gb       1gb (20%)     4gb (80%)     1:4
Today:           1.2gb     400mb (33%)   800mb (66%)   1:2

如果我的数学运算有误,请原谅我,这就是为什么我想要一个工具;)

我主要对 Linux(CentOS 6)主机感兴趣,但任何 Windows(2008R2)工具也会有用。

我发现一个线程建议netstat -s -6 | grep -i octets但该-6选项在 CentOS 6 上无效;我猜它是 netstat 的最新添加内容。

答案1

我已经这样做了,并且已经使用了一段时间穆宁以及我自己编写的自定义插件,它从iptables审计规则中获取数据。它在 C6 盒子上运行,所以如果没有更好的想法,你应该能够将它移植到位。它不是你想要的简单的一行程序,但它可以工作,并产生如下数据:

网络吞吐量的 munin 图

该插件非常简单,它仅从创建的两个平面文件中获取数据/var/tmp

#!/bin/bash
#
# (c) Gatekeeper Technology Ltd., 2013
# May be used under the terms of GPLv3 or, at your discretion, any later version

if [ "$1" = "config" ]; then

    echo 'graph_title Network Throughput'
    echo 'graph_category network'
    echo 'graph_info This is the total throughput on the NIC since the beginning of the calendar month, or the last reboot, whichever was mo
st recent.'
    echo 'graph_vlabel bytes'
    echo 'graph_args --logarithmic'
    echo 'in4.label       in v4'
    echo 'in4.colour      ff0000'
    echo 'out4.label      out v4'
    echo 'out4.colour     00ff00'
    echo 'in6.label       in v6'
    echo 'in6.colour      aa0088'
    echo 'out6.label      out v6'
    echo 'out6.colour     00aa88'
    echo 'total.label     total'
    echo 'total.colour    0000ff'
    exit 0
fi

out=`head -3 /var/tmp/audit.out.counts | tail -1 | awk '{print $2}'`
echo "out4.value $out"
in=`head -3 /var/tmp/audit.in.counts | tail -1 | awk '{print $2}'`
echo "in4.value $in"

out6=`head -3 /var/tmp/audit.out.v6.counts | tail -1 | awk '{print $2}'`
echo "out6.value $out6"
in6=`head -3 /var/tmp/audit.in.v6.counts | tail -1 | awk '{print $2}'`
echo "in6.value $in6"

total=$(($in+$out+$in6+$out6))
echo "total.value $total"

使它们看起来像这样的 crontab 条目:

# output the audit rule counts for munin purposes
* * * * *  /sbin/iptables  -L AUDIT-I -n -x -v > /var/tmp/audit.in.counts
* * * * *  /sbin/iptables  -L AUDIT-O -n -x -v > /var/tmp/audit.out.counts
* * * * *  /sbin/ip6tables -L AUDIT-I -n -x -v > /var/tmp/audit.in.v6.counts
* * * * *  /sbin/ip6tables -L AUDIT-O -n -x -v > /var/tmp/audit.out.v6.counts
# and zero the counts once a month
0 0 1 * *  /sbin/iptables  -Z AUDIT-I
0 0 1 * *  /sbin/iptables  -Z AUDIT-O
0 0 1 * *  /sbin/ip6tables -Z AUDIT-I
0 0 1 * *  /sbin/ip6tables -Z AUDIT-O

iptables制定了以下规则/etc/sysconfig/iptables

:AUDIT-I - [0:0]
:AUDIT-O - [0:0]
# audit input traffic
-A INPUT -i eth0 -j AUDIT-I
 [ALL OTHER INPUT RULES APPEAR HERE, AFTER THE AUDIT RULE]
# audit outbound traffic
-A OUTPUT -o eth0 -j AUDIT-O
 [ALL OTHER OUTPUT RULES APPEAR HERE, AFTER THE AUDIT RULE]
# AUDIT rules
-A AUDIT-I -p all
-A AUDIT-O -p all

这样做的原因crontab是为了阻止 munin 插件需要以 root 权限运行;如果您不介意这样做,您可以让插件通过调用iptables自身直接获取数据包计数。

计数在重启后不会保留(因此上图中的计数额外下降到零),但如果您将服务器设置为保存iptables规则和数据包计数重新启动时,这不会影响您。

答案2

你可以在 GitHub 上尝试这个 IPv6 Munin 插件:

https://github.com/MorbZ/munin-ipv6

相关内容