16

I installed vnstat on my Ubuntu 14.04 server to track my internet usage (I have a limited monthly transfer). The database never updates, however. I've tried uninstalling/reinstalling, but that doesn't work. What do I need to do to get vnstat to update and be accurate?

14

Run

sudo chown -R vnstat:vnstat /var/lib/vnstat

This fixed my problem on Ubuntu 14.04.

Make sure you have following files in that folder and have proper ownership.

boby@fwhlin:/var/lib/vnstat$ ls -la
total 16
drwxr-xrwx  2 vnstat vnstat 4096 May 16 01:50 .
drwxr-xr-x 78 root   root   4096 Jul 22 15:14 ..
-rw-r--rwx  1 vnstat vnstat 2792 Jul 26 00:26 eth0
-rw-rw-r--  1 vnstat vnstat 2792 Jul 26 00:26 .eth0
boby@fwhlin:/var/lib/vnstat$ 

.eth0 is temp file, that may disappear sometimes.

7

After installing vnstat the database need to be created (one time). To create the database you can use the update switch, which create new database in the base of no database. Create DB: sudo vnstat -i eth0 -u where eth0 is the name of the network interface. If you are unsure update for all interfaces by sudo vnstat -u. After sometime (1 minute) you can view the details vnstat -i eth0 or simply vnstat .

Update

It seems vnstat not running ! . Start the daemon by running sudo /etc/init.d/vnstat start and check for the result after 5 minutes.

Example

sudo vnstat -u -i eth0

Error: Unable to read database “/var/lib/vnstat/eth0. Info: -> A new database has been created.

sudo /etc/init.d/vnstat start
  • Starting vnStat daemon vnstatd [ OK ]

Once database have been initialiase, its ready to monitor bandwidth usage. You can view the report by invoke command vnstat.

  • @Vaindil, did you tried this? – totti Jul 27 '14 at 12:04
  • 1
    Yes, I did do this after I installed vnstat. Doing vnstat does show the output, but it shows that the database hasn't been updated in weeks. – vaindil Jul 28 '14 at 15:42
  • Does vnstat running ? What's the output of ps aux | grep vnstat – totti Jul 28 '14 at 15:56
  • steven 6475 0.0 0.1 11744 916 pts/0 S+ 13:35 0:00 grep --color=auto vnstat (vnstat shows up red in the terminal, if it matters or helps) – vaindil Jul 30 '14 at 17:36
  • When attempting to run sudo /etc/init.d/vnstat start, I get the following: Starting vnStat daemon: vnstatd. / pidfile: No such file or directory and then it sits as if it's doing something, but it sits indefinitely. – vaindil Jul 31 '14 at 18:14
2

Are you sure that vnstatd is running, i.e. the daemon (background process) that does the data collection? If not, check with

ps aux | grep vnstatd

You should see it there.

For me, after upgrading to 14.04 vnstatd kept crashing on start-up.

My solution was to remove the folder it uses to store its data (/var/lib/vnstat) and create a new empty directory instead. You may need to run vnstatd manually once to create the database after that:

vnstatd -n -s

Apart from that, I also needed to apply

sudo chown -R vnstat:vnstat /var/lib/vnstat

as suggested by HostOnNet.

1

Same issues here.

After checking the details it turned out that the databases for the different devices (eth0, ppp0, wlan0, etc.) were created in /var/lib/vnstat but these files were owned by the USER. After sudo chown -R vnstat:vnstat /var/lib/vnstat it seems to be ok. I also had to check the default interface in /etc/vnstat.conf - it was the wrong one for me, so I just changed it.

  • I forgat to add that I let run "vnstat -u -i wlan0" (and same for the other devices) as ROOT. This could also cause issues with permission. And one more thing: You have to check whether you are using systemd, init or upstart and start the daemon according to this. – bradley Jan 19 '16 at 14:36
1

Sorry I had to make this its own answer instead of editing Boby's since my edit was rejected :|

By default, when you install vnstat, it auto starts a vnstatd daemon, which collects metrics every 30 seconds and "updates them" (for all local devices) every 5 minutes. So in essence, after installing vnstat packet, you should start to see metrics 5 minutes later.

Appears to sometimes be a problem with the install package however. It sometimes seems to create /var/lib/vnstat directory in such a way that it isn't writable by user vnstat so vnstat program only works when run as root (the daemon runs as user vnstat).

You can check if this is your problem by running this:

ll /var/lib | grep vnstat
drwxr-xr-x 2 root        root        4096 Oct 25  2014 vnstat

If it is owned by root (as it is in this example), then that may be your problem. You can also look for the cause in your /var/log/syslog file, it'll probably have lines like this:

Jul 27 22:06:19 xxx vnstatd[13276]: Error: Unable to open database "/var/lib/vnstat/eth0" for writing: Permission denied

Run

 sudo chown -R vnstat:vnstat /var/lib/vnstat

This fixed my problem on Ubuntu 15.10.

Make sure you have following files in that folder and have proper ownership, should look like this when you're done:

/var/lib/vnstat$ ls -la
total 16
drwxr-xrwx  2 vnstat vnstat 4096 May 16 01:50 .
drwxr-xr-x 78 root   root   4096 Jul 22 15:14 ..
-rw-r--rwx  1 vnstat vnstat 2792 Jul 26 00:26 eth0
-rw-rw-r--  1 vnstat vnstat 2792 Jul 26 00:26 .eth0

You may need to restart your vnstat daemon via sudo /etc/init.d/vnstat restart if it died from its initial failed startup attempt. You should start getting data for all devices in 5 minutes after the fix.

0

Try to output some from this help:

$ vnstat --help
 vnStat 1.11 by Teemu Toivola 

         -q,  --query          query database
         -h,  --hours          show hours
         -d,  --days           show days
         -m,  --months         show months
         -w,  --weeks          show weeks
         -t,  --top10          show top10
         -s,  --short          use short output
         -u,  --update         update database
         -i,  --iface          select interface (default: eth0)
         -?,  --help           short help
         -v,  --version        show version
         -tr, --traffic        calculate traffic
         -ru, --rateunit       swap configured rate unit
         -l,  --live           show transfer rate in real time

See also "--longhelp" for complete options list and "man vnstat".

READ MORE

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.