# measuring internet traffic

## MOS-FET

hi does anybody know a small simple tool that just measures how many megabytes i down-/upload from/into the internet? i have a volume-based internet connection, means i have an adsl connection with 5 gb/month free and have to pay for every extra mb when these 5 gb are used up, so i just want to know how many mb's i've already "used".

thanks

tom

----------

## _puck_

As usual within Opensource, you have varoius fine options:

- snmp -> mrtg/rrdtool/cacti would be the simplest

- a own script, which greps this from the ifconfig line and make a grand total, likewise write it in an rrd

```

          RX bytes:3502700521 (3340.4 Mb)  TX bytes:233097935 (222.2 Mb)

```

- iptraf, if you would like to sort your traffic 

```

*** TCP/UDP traffic log, generated Sun Dec  7 12:05:02 2003

TCP/80: 596 packets, 189095 bytes total; 351 packets, 109775 bytes incoming; 245 packets, 79320 bytes outgoing

UDP/53: 176 packets, 20464 bytes total; 88 packets, 6343 bytes incoming; 88 packets, 14121 bytes outgoing

TCP/443: 60 packets, 16923 bytes total; 33 packets, 4407 bytes incoming; 27 packets, 12516 bytes outgoing

TCP/110: 238 packets, 27844 bytes total; 114 packets, 7645 bytes incoming; 124 packets, 20199 bytes outgoing

TCP/22: 4 packets, 208 bytes total; 2 packets, 104 bytes incoming; 2 packets, 104 bytes outgoing

UDP/68: 2 packets, 675 bytes total; 1 packets, 347 bytes incoming; 1 packets, 328 bytes outgoing

UDP/67: 2 packets, 675 bytes total; 1 packets, 328 bytes incoming; 1 packets, 347 bytes outgoing

```

Depending on your needs and the time you are willing to offer for this topic, you may choose the "right" one. If you know, what you want, and need help, give me a hint.

----------

## silverter

net-analyzer/vnstat (http://torus.lnet.lut.fi/vnstat/)

I use ist all the time... this is an exerpt of the output:

```
eric@lion eric $ vnstat

Database updated: Sun Dec  7 18:25:00 2003

 

        eth0

 

           received:            272 MB (95.4%)

        transmitted:             13 MB (4.6%)

              total:            285 MB

 

                        rx     |     tx     |  total

        -----------------------+------------+-----------

        yesterday        14 MB |       1 MB |      15 MB

            today        33 MB |       1 MB |      34 MB

        -----------------------+------------+-----------

        estimated        42 MB |       1 MB |      43 MB

```

----------

## MOS-FET

hi! thanks for all your posts. well vnstat looks very promising, but how do i use it? i've emerged it and started it with "vnstat -i ppp0" and it says "nothing to do". when i try any other options, it just tells me that no database was found in /var/spool/vnstat. i have write permission to this dir and ppp0 is up. do i have to initialize vnstat first? if yes, how?

tom

----------

## Duffy

try 

```
vnstat -D
```

 should initiate the database

----------

## MOS-FET

hmm, i get the following output when i type vnstat -D:

arg 1: "-D"

Nothing to do. Use -h for help

i have vnstat 1.1 installed! :-(

tom

----------

## Duffy

hm me to, i did "vnet -i eth0" then "vnet -D"

maybee you need the --enable thing

----------

## Vergo

 *MOS-FET wrote:*   

> hi! thanks for all your posts. well vnstat looks very promising, but how do i use it? i've emerged it and started it with "vnstat -i ppp0" and it says "nothing to do". when i try any other options, it just tells me that no database was found in /var/spool/vnstat. i have write permission to this dir and ppp0 is up. do i have to initialize vnstat first? if yes, how?
> 
> 

 

Don't use that ebuild, it's not mine and it's broken. I still don't understand why it's in portage since a working ebuild existed even before it. So my advice for now: unmerge that vnstat you got from the ebuild and get the source package.

Here's a really quick install instruction:

```
cd /usr/src

wget http://torus.lnet.lut.fi/vnstat/vnstat-1.2.tar.gz

tar zxvf vnstat-1.2.tar.gz

cd vnstat-1.2

make

make install
```

and since you plan to use ppp0 that's not probably always up, do also the following (in that /usr/src/vnstat-1.2 dir)

```
cat pppd/vnstat_ip-up >>/etc/ppp/ip-up

cat pppd/vnstat_ip-down >>/etc/ppp/ip-down
```

Now you can finally execute

```
vnstat -u -i ppp0
```

and it should start working. Just remember that you'll have to wait 5 min. and at least 1MB to get some results.

----------

## swimmer

And here is a quick install instruction with a new ebuild  :Smile: 

```
cd /usr/portage/net-analyzer/vnstat/

cp vnstat-1.1.ebuild vnstat-1.2.ebuild

ebuild.sh vnstat-1.2.ebuild digest

emerge vnstat-1.2.ebuild -vp

emerge vnstat-1.2.ebuild -v

mkdir /var/lib/vnstat

vnstat -u
```

And for collecting data I put the following line in /etc/crontab

```
# collecting traffic data

0-55/5 * * * * root    if [ -x /usr/bin/vnstat ] && [ `ls /var/lib/vnstat/ | wc -l` -ge 1 ]; then /usr/bin/vnstat -u; fi
```

Enjoy it  :Wink: 

Stefan

----------

## monotux

 *swimmer wrote:*   

> And here is a quick install instruction with a new ebuild 
> 
> ```
> cd /usr/portage/net-analyzer/vnstat/
> 
> ...

 

thank you!

this helped me make vnstat work  :Smile: 

----------

## Vergo

 *furiorc wrote:*   

> this helped me make vnstat work 

 

I hope you used version 1.4 and not that 1.2 mentioned above.  The ebuild in portage for 1.4 is otherwise ok, but a broken crontab gets installed. Maybe some developer could finally look at bug #60711 because that's a simple thing to fix.

----------

