Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Jun 2002 15:10:15 +0300
From:      "Artyom V. Viklenko" <artem@mipk-kspu.kharkov.ua>
To:        Wincent Colaiuta <wincentcolaiuta@mac.com>
Cc:        freebsd-isp@FreeBSD.ORG
Subject:   Re: Bandwidth billing and measurement scripts
Message-ID:  <3D0F2327.FDF97290@mipk-kspu.kharkov.ua>
References:  <F579D533-82AF-11D6-9899-003065C60B4C@mac.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Wincent Colaiuta wrote:
> 
> Hi
> 
> Can anybody provide me a pointer to some scripts for the purposes of
> measuring and billing bandwidth use on a server using ipfw? I've heard
> it suggested several times as an easy way to measure/bill traffic but
> I've yet to encounter any examples on the web of how to do it.
> 

Here is some example from my external router.
In order to count traffic amount on external interface to provider
I place these rules:

ipfw add 2000 count ip from any to any in recv ed1
ipfw add 2001 count ip from any to any out xmit ed1

'ipfw show 2000 && ipfw show 2001' produce this output:

02000 3226667 1630960688 count ip from any to any in recv ed1
02001 3127782  917406180 count ip from any to any out xmit ed1

Second and third fields are packet and byte counters.
You can use them in any scripting language ( awk, perl, etc )
to make your billing actions.

Unfortunately I drop thes scripts, and now I have sample
script using SNMP. But concept is the same.

The only one problem is that if you reboot your router all
counters are zeroed. Tnus you have to write script which will
be executed via cron regularly (say, every 10 minutes) and
check current values, previous saved somevhere values and make
desision what to do:

a) if current value less than old value, there was a reboot in place
and new delta is current value.

b) else delta = current value - old value.

 Then add this delta to previously saved total counter.

with 'ipfw zero xxx' you can reset counters (also from cron, for exaple,
on midnight every first day of month).

I use perl and hash arrays associated with dbm files to store
all values for future reference.

Hope this will be helpful as some starting point. :)

-- 
       Sincerely yours,
                         Artyom V. Viklenko.
======================================================
System Administrator        artem@mipk-kspu.kharkov.ua
------------------------------------------------------
IIAT NTU "KhPI" 21, Frunze Str., Kharkov Ukraine 61002
Phone: +380 (572) 400026        Fax: +380 (572) 474062
======================================================

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-isp" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3D0F2327.FDF97290>