# Need a bandwith moniter

## Nebetsu

I've been having issues with using too much bandwidth and would like something that I can run in the background that will measure my usage and save it so I know how much I'm using a month. Are there any tools like that?

----------

## jhmartin

http://www.cacti.net/

http://oss.oetiker.ch/mrtg/

----------

## Ast0r

 *Nebetsu wrote:*   

> I've been having issues with using too much bandwidth and would like something that I can run in the background that will measure my usage and save it so I know how much I'm using a month. Are there any tools like that?

 

ntop

iptraf+rrdtool

Of the two, ntop is far easier to set up and it's easier to get lots of detailed graphs and bandwidth usage data. You'll have to unmask ntop though. I installed it on my router last night and so far it hasn't crashed, so maybe it's relatively stable now.

Keep in mind that any tools that analyze the packets sent over your interfaces will use some CPU. On a Sempron 2400 box, I was pulling data at about 100Mbps and the CPU usage for iptraf was about 40%. Also, the more interfaces you are monitoring, the more CPU you will use. On my router here @ home (800mhz P3), ntop has used about 24 minutes of CPU time in the last 12 hours to monitor two interfaces (keep in mind that almost all traffic hits both intefaces ... if I was only monitoring one, then it would be using about half that). You can tweak ntop to use less CPU/disk IO by reducing the frequency that it updates the rrd database, but it is still going to use a decent amount to analyse the packets.

Ntop is really better-suited to run on a router/bridge that on a personal computer or a webserver, but it will work.Last edited by Ast0r on Thu Oct 12, 2006 11:42 pm; edited 1 time in total

----------

## Nebetsu

Is there one that isn't for routers? I just want one for my desktop computer.

----------

## Ast0r

 *Nebetsu wrote:*   

> Is there one that isn't for routers? I just want one for my desktop computer.

 

How do you know that it's not other people on your network using the bandwidth? I like to monitor the whole network, personally. Plus, running a program to keep aggregate bandwidth usage will use some CPU on your computer; it's far better to do it at the router, but whatever.

----------

## Nebetsu

I don't have a Linux router. And the only other person on the network is a 266MHz with a few 4 gig drives.

----------

## dspgen

cat /proc/net/dev

shows stats since you booted. 

Logging the contents of that every hour takes no cpu and can be summed with a little greping and gawking   :Wink: 

----------

## Nebetsu

 *dspgen wrote:*   

> cat /proc/net/dev
> 
> shows stats since you booted. 
> 
> Logging the contents of that every hour takes no cpu and can be summed with a little greping and gawking  

 

How would I set that to log every hour?

----------

## dspgen

 *Nebetsu wrote:*   

> 
> 
> How would I set that to log every hour?

 

in /etc/cron.hourly

make a file with this:

```

#!/bin/bash

interface="eth0"

fname=/var/log/${interface}.log

btime=$(cat /proc/stat|grep 'btime'|gawk '{print $2}')

received=$(cat /proc/net/dev |grep ${interface}|gawk -v FS="[ :]*" '{print $3}')

sent=$(cat /proc/net/dev |grep ${interface}|gawk -v FS="[ :]*" '{print $11}')

datec=$(date +'%Y.%m.%d.%H.%M.%S')

if [ -n "$(grep ${btime} ${fname})" ]; then

    sed -i '$d' ${fname}

fi

echo "${btime} ${datec} ${received} ${sent}" >> ${fname}

echo "${btime} ${datec} ${received} ${sent}" >> ${fname}.all

gawk '{r = r + $3; s = s + $4; printf("received:%d sent:%d\n", r,s)}' ${fname}|tail -1

```

that assumes eth0 is the interface you want to log.

You can run it yourself to see what the current sum is.

----------

## dspgen

two problems with that script I wrote:

ptime wobbles - boot time can vary by more than a second, and it changes when the clock changes.

received and sent bytes rollover at 4G.

The script gets a little messy (at least with my limited bashing skills) when those are taken into account.

----------

## cazbar

I used to use vnstat when I had a linux box acting as my router. It's command line only but it worked well. I think it could fit your purpose.

----------

## fuqnbastard

I use two tools with a command line interface

bmon - for graphing and traffic change over time

nethogs - to break it up between different running programs (needs a lot of CPU)

----------

## Massimo B.

nethog doesn't show any bandwidth other then 0.0.

nload and iftop work fine. I set all three tools on the same interface eth1.

```

## nethog eth1

PID USER     PROGRAM                      DEV        SENT      RECEIVED

0     root     unknown                                 0.000       0.000 KB/sec

## nload eth1

## iftop -i eth1

##  ...work fine and show traffic.

```

I would like to see bandwidth for processes, therefore nethog.

PS: That seems to be a ppc specific bug.

----------

