On Wed, Jun 20, 2007 at 09:24:16PM -0400, Arnaud Bergeron wrote:
> I have a problem where I need to know how much traffic has passed on a
> given interface.  I don't need it broken down by IPs, protocols or
> whatever of the sort.
> 
> After a bit of research I discovered the SIOCGIFDATA ioctl that seems
> to do what I want.
> 
> I built myself a little test application to try it out (see at the end
> of the mail for the code).  The number it reports for my egress
> interface are weird though:
> 
> $ ./ifbw pppoe0
> bandwidth: 802865637b up 1907983523b down
> reduced: 765.67MiB up 1.78GiB down
> 
> I am certain I downloaded at least 2.6GB in the last few days and
> uploaded at least 3.2GB.  Also, for the outbound traffic shaping queue
> I have over this interface pftop reports 33Gb of traffic.
> 
> So I have questions for the network gurus.  Am I doing something
> incorrectly with my code below?
> If not, are the counters just out of whack and it's normal?
> 
> Also, if anybody knows a better way to do this, please tell me.
> 

The if_data counters are defined as u_long which wrap at around 4.5GB.
You need to use your own absolute counter and poll if_data from time to
time. Switching to 64bit counters is not trivial but it will happen.

-- 
:wq Claudio

Reply via email to