Vnstat to monitor the network
Written by edmond in Applications, Controls & Shell, Gnu-Linux, Security, Tips & TricksV nState is an excellent open source tool for monitoring your network. It is not a sniffer, it deals only store in a db file, the information in / proc. Can be used in a text and not only, without root privileges. To install it just for a:
apt-get install libgd2-xpm vnstat
To have a graphical interface:
wget http://www.sqweek.com/sqweek/files/vnstat_php_frontend-1.4.tar.gz
unpack it in / var / www
cd / var / www
tar xvzf vnstat_php_frontend-1.4.tar.gz
For convenience we change the name
mv vnstat_php_frontend-1.4 vnstat
At this point we begin to create the db, depending on the number of interface and the name:
vnstat-u-i eth0
or
vnstat-u-i eth0 & & vnstat-u-i eth1
After 5 minutes, giving a terminal vnstat, we begin to see the statistics. To see them in a more convenient:
http://localhost/vnstat/
Post similar (or almost):
- Changing MAC address on Linux to change our MAC address must not do more ...
- Improving Iceweasel or Firefox Is it possible to make improvements to Iceweasel e. ..
- Encrypt files with GPG / GnuPG to use GPG is another way ...

















July 16th, 2009 at 01:58
Hello, I was part vnstat and I created a database on a WiFi connection. But now I want to create one for an internet connection through usb stick, but I can not. I tried with:
David @ aspire: ~ $ vnstat-i USB0
and I returned:
Error:
Unable to read database "/ var/lib/vnstat/USB0.
USB0: Not enough data available yet
Is normal, because the database does not yet exist, but how do I create it? Thank you!
July 16th, 2009 at 21:03
Sorry you've already created a db to a WiFi connection, with a PCI card, now you want to create another db to another wifi connection but with USB dongle. Is that correct?
July 17th, 2009 at 08:37
Er, I do not know .. :)
Now I try to tell you atecnicamente, my own words. I had a wifi connection to the modem router and I created a database on it. Now I got a USB stick (a Huawei HSDPA Stick, so to speak) and I monitor the connection, since the contract with my manager provides a level of monthly traffic. I assume that the database created with the previous connection wifi (wlan0) does not give me details of the new connection, the name must be USB0, so I want to create a new database to check the traffic.
July 17th, 2009 at 22:04
Ok now I understand .... But you appear in ifconfig USB0 or something else? It 'clear that the db should be created for the Huawei stick.
Try vnstat-u-i USB0 or vnstat-u-i pan0.
July 18th, 2009 at 18:41
Meanwhile, thank you very much, eventually could become a kind of forum staff and I would not want to abuse your kindness ..
However.
The output of ifconfig is:
eth0 Link encap: Ethernet HWaddr 00:1 e: 68: a4: e7: 43
UP BROADCAST MULTICAST MTU: 1500 Metric: 1
RX packets: 0 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 0 errors: 0 dropped: 0 overruns: 0 carrier: 0
collisions: 0 txqueuelen: 1000
RX bytes: 0 (0.0 B) TX bytes: 0 (0.0 B)
Interrupt: 251 Home address: 0 × 6000
lo Link encap: Local Loopback
inet address: 127.0.0.1 Mask: 255.0.0.0
address inet6::: 1 / 128 Scope: Host
UP LOOPBACK RUNNING MTU: 16436th Metric: 1
RX packets: 1727 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 1727 errors: 0 dropped: 0 overruns: 0 carrier: 0
collisions: 0 txqueuelen: 0
RX bytes: 50782 (50.7 KB) TX bytes: 50782 (50.7 KB)
ppp0 Link encap: Point-to-Point Protocol
inet address: 10.102.13.59 PtP: 10.64.64.64 Mask: 255.255.255.255
POINTOPOINT NOARP UP RUNNING MULTICAST MTU: 1440 Metric: 1
RX packets: 9 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 10 errors: 0 dropped: 0 overruns: 0 carrier: 0
collisions: 0 txqueuelen: 3
RX bytes: 174 (174.0 B) TX bytes: 213 (213.0 B)
wlan0 Link encap: Ethernet HWaddr 00:22:69:0 d: 8e: 78
inet address: 192.168.1.52 Bcast: 192.168.1.255 Mask: 255.255.255.0
address inet6: fe80:: 222:69 ff: fe0d: 8e78/64 Scope: Link
UP BROADCAST RUNNING MULTICAST MTU: 1500 Metric: 1
RX packets: 24328th errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 20642nd errors: 0 dropped: 0 overruns: 0 carrier: 0
collisions: 0 txqueuelen: 1000
RX bytes: 14633157 (14.6 MB) TX bytes: 3915820 (3.9 MB)
wmaster0 Link encap: UNSPEC HWaddr 00-22-69-0D-8E-78-65-37-00-00-00-00-00-00-00-00
UP BROADCAST RUNNING MULTICAST MTU: 1500 Metric: 1
RX packets: 0 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 0 errors: 0 dropped: 0 overruns: 0 carrier: 0
collisions: 0 txqueuelen: 1000
RX bytes: 0 (0.0 B) TX bytes: 0 (0.0 B)
The output of vnstat-u-i USB0 (which I had already tried) is this:
Error:
Unable to read database "/ var/lib/vnstat/USB0.
Error:
Unable to get interface statistics.
The output of vnstat-u-i pan0 is this:
Error:
Unable to write database "/ var/lib/vnstat/pan0.
Make sure it's write enabled for this user.
Database not updated.
and also with sudo-u-i vnstat pan0 the question remains, why did not return output, apart after the first time that I give the command, which tells me you have created a db.
July 18th, 2009 at 19:44
I hope you have tried to do too
vnstat-u-i ppp0
since the modem connection is this.
July 18th, 2009 at 22:42
Obviously I had not done. Now that I've done I think we are!
:)
Thanks again
July 23rd, 2009 at 23:02
Hello Edmond,
I tried your guide on a Ubuntu 8.04 .. little problem terminal command vnstat me the data while at Site I do not see anything ....
How to attach / db which I check the server for the html page? (I state that I see the page but no data)
Hello
July 23rd, 2009 at 23:58
mmm little other info. ...
Installed from the command line and work them ... but if I wanted to remove a card from the monitor?
July 24th, 2009 at 21:34
Hello i live in db / va / lib / vnstat, simply enter in as root and delete what you do not need. Regarding your first question, I'm experiencing.
July 26th, 2009 at 18:27
I confirm it works ... thanks latest version are not exactly inserted db.
them anyway you can add and eliminira cards
Thanks
July 27th, 2009 at 21:15
by dint of research I trvato the way ... then the db is saved in the / var / lib / vnstat / inside there are files for each card ... just remove ...
Hellooo
July 27th, 2009 at 21:22
or re-read the answers ... well I must correct because I assume you have created confusion. ...
to remove the interfaces just remove the db with the correct name in the directory / var / lib / vnstat /
for the problem that a web not seen the data, just go to / var / www / vnstat / config.php and look for the line containing $ vnstat_bin = "; and make it ... $ vnstat_bin = '/ usr / bin / vnstat ';
Edmond thank you and excuse the confusion