Installing vnstat Bandwidth Monitoring in CentOS 6 / RHEL 6

One of the most important aspects of system administration these days is monitoring the traffic on your server. Many hosting providers impose limits on how much you can transfer per month. If you go over these limits, it’s not really a problem from the data center’s point of view, but you will usually end up getting slapped with a fee per GB you transfer in excess of your limits. This can add up quickly if you have a busy site. It’s not only restrictions either. Abnormal bandwidth usage could alert you to a problem on the server, such as an exploit or some other unauthorized wasteful activity.

Vnstat is a neat little tool to help monitor your bandwidth usage. It is found in the EPEL Linux repositories. After doing some Googling, I found there aren’t many good tutorials on installing and configuring vnstat out there.

vnstat

To start, you will need to enable the EPEL repositories for your version of Linux. To enable the EPEL repositories in CentOS/RHEL 6

Next, you can install vnstat as normal through yum.

Once installed, the default configuration will work for most people. The default will run on the eth0 interface. If you need to change the interfaces, you will need to edit two files. It’s self explanatory. Change the occurrences of eth0 to eth1 (or your choice of interface).

Next, we need to create the database where the data will be collected and stored. The command may generate an error. If it does, that’s fine. It is because the new file is created with ownership of the logged in user (we are using root). We will fix this by running a chown on the file before starting the service. Again, if you’re using eth1 or another interface, make sure you replace it in the command below.

That’s it. You’re ready to start the service and start collecting data.

It may take a couple of hours for data to be ready to view. You can view bandwidth usage based on hour, day, week, or month. If you’re inpatient, like I often am, you can restart the vnstat service after running for a few minutes. This will force it to load the stats so far and give you some to look at.

 

 

Leave a Reply