# Bandwidth Utilization Monitoring



## jperalta (Jul 21, 2011)

Hi,

I'm attempting to use `systat -ifstat` to monitor total bandwidth utilization since uptime. It appears to rollover totals to 0 after 4GB or so. Is this a design "feature" or a datatype limitation? Either way, is there any way this can be fixed so that it never rolls over after startup?


----------



## pbd (Jul 26, 2011)

systat() seems to read number of total incoming/outgoing bytes from [font="Courier New"]ifi_ibytes[/font]/[font="Courier New"]ofi_ibytes[/font] witch is defined in /usr/src/sys/net/if.h as *u_long*, witch has maximal value [font="Courier New"]+4,294,967,295[/font] on 32-bit system.

You can try changing /usr/src/sys/net/if.h from:


```
u_long  ifi_ibytes;     /* total number of octets received */
    u_long  ifi_obytes;     /* total number of octets sent */
```

to:


```
uint64_t ifi_ibytes;     /* total number of octets received */
    uint64_t ifi_obytes;     /* total number of octets sent */
```

And then recompile and reinstall kernel and world, *but do it at your own risk! I'm not programmer and certainly don't understand FreeBSD internals.* You can and up with something terribly wrong (if it will even compile). I am not even sure what is *uint64_t*, I'm just guessing..


----------



## pbd (Jul 27, 2011)

... but better idea is to use some tool like net/vnstat, net-mgmt/darkstat, etc.


----------



## mix_room (Jul 27, 2011)

jperalta said:
			
		

> It appears to rollover totals to 0 after 4GB or so. Is this a design "feature" or a datatype limitation?


Data type limitation. 




> Either way, is there any way this can be fixed so that it never rolls over after startup?


Not by using a simple data-type. By using more complex forms it should be possible, but the question is if it is really necessary. 
Why would you want to monitor bandwidth usage since uptime? Most billing is per time slice [day/month/year]. 

Or as suggested us another tool. I personally like rrdtool


----------



## jperalta (Jul 27, 2011)

net/vnstat seems to do exactly what I want without any internal mucking. Thanks for the help.


----------



## nixcz (Sep 23, 2011)

I know this is an old thread, but this thread got me looking into vnstat and trying it on FBSD 9, where I found it didn't work.  I don't know if I'm the only one seeing the problem, but I was able to reproduce the failure on 3 different systems.

I also found a quick fix to get it working, but I have no idea what the proper fix is.  Posted here: http://forums.freebsd.org/showthread.php?t=26557

I'm replying on this thread in the hopes of attracting some attention to the issue and seeing if anyone else is running into it, or if I'm the only one.  (It's unlikely, but it is possible something in my environment is causing the failure, as I configure all my machines similarly.)


----------



## ecazamir (Sep 27, 2011)

I assume that /usr/bin/netstat should be useful, if no one resets the byte counter of an interface.

```
# netstat -I bge0 -b
Name    Mtu Network         Address           Ipkts Ierrs Idrop     [color="Red"]Ibytes[/color]    Opkts Oerrs     [color="Red"]Obytes[/color]  Coll
bge0   1500 <Link#1>        00:17:xx:xx:xx:x6 370483446     1     0 [color="Red"]527101228430[/color] 192314676     0 [color="Red"]13435419798[/color]     0
bge0   1500 89.yy.yy.yy/28  hostname          16297348     -     - 4219802314    81155     -    7108355     -
```
Using this, combined with /usr/bin/awk should give the expected results:

```
# netstat -I bge0 -b | awk '{ if (/Link/) { print "Bytes in: ", $8, "\nBytes out: ", $11 } }'
Bytes in:  527158339782 
Bytes out:  13436371183
```


----------

