Use ‘vnstat’ in openSUSE (12.2) to monitor network bandwidth usage

Despite the fact that it’s a command-line based tool (but extremely easy to use!) ‘vnstat’ is one of my favorite tools for monitoring the bandwidth usage of network connections. Now I’ve written about it already (under Ubuntu) but because the installation is a bit hectic under openSUSE 12.2, I decided to write about how to install and configure it properly in openSUSE.

Firstly, it is located in a different repository called ‘server monitoring’ in openSUSE, so first we have to add it. Secondly unlike in Ubuntu, openSUSE does not let vnstat’s service to be run from the background and start monitoring your networks.

So you either have to create a database for your preferred network interface manually or can just enable its system service (daemon), which is the most easiest, as a fix. So here it goes.

Step 1:

Enabling the ‘server monitoring’ repository.

If you use the latest version of openSUSE 12.2, then enter the below command in your Terminal.

Step 3: Now I’m using openSUSE 12.2 and don’t know if in other versions you have to configure ‘vnstat’ manually too (no need in Ubuntu). If for some reason few seconds after installing, ‘vnstat’ is not showing your network bandwidth usage, then you might have to configure it manually.

Step 4: So to enable the system service of ‘vnstat’ (which should solve the issue) then first search for ‘system services’ in the start menu and launch the ‘system service editor’ tool.

Step 5: Then scroll down a bit and find a service called ‘vnstatd’ as shown below.

Once you’ve found it, select it and click on the ‘Enable’ button. Click ‘OK’ to the next message that you get (make sure it says something like ‘returned success (0) …’). And then click on the other ‘OK’ button on the right bottom side and then choose ‘Yes’ to the next message to confirm.

That’s it. From now on you should be able to view your network usage by simply typing ‘vnstat’ on your Terminal window.

Optional (?)

If however, even after doing all that and once entered ‘vnstat’ you got an error saying something like …

No database found, nothing to do. Use --help for help …

Step 6: Then perhaps you’ll have to manually create a database for your network interfaces. For example, if you want ‘vnstat’ to monitor your Wi-Fi connection then enter the below command to create a database for that (remember, you only have to create a database once).

sudo vnstat-create-db wlan0

If you have a wired (Network card) connection, then enter the below command to create a database.

sudo vnstat-create-db eth0

Then wait for few seconds (about 30-35 seconds) and issue ‘vnstat’ command and you should see an output as shown in the first screenshot.

Ho to change the update interval?

By default, ‘vnstat’ updates network traffic data within an interval of 30 seconds. But if that’s not fast enough for you, then you can easily change that. For that enter the below command in your Terminal.

sudo nano /etc/vnstat.conf

This should open the main configuration file of ‘vnstat’ in an editor. Now scroll down and find a line that says ‘UpdateInterval 30′. Simply replace ’30’ with the amount of seconds that you want ‘vnstat’ to update its database (don’t change anything else) as shown below.

Well, if you just typed 'vnstat' then it'll show the total bandwidth for all of your network interfaces (devices). But you can retrieve the bandwidth of the individual devices by using its proper network interface name.

As for your question, to get the bandwidth of your network card you can use the below command.

vnstat -i eth0

If you have more than one card then replace 'eth0' with 'eth1', 'eth2' etc.

But please remember that 'vnstat' only shows you the traffic since the day it was installed (not before that).

And the 'Switch' will show you all the traffic from the day, it was installed on your Network which should be why there's a difference in the traffic counts (if I understand your question) …