Server Administration & Management

Protected: bandwidth.sh

This content is password protected. To view it please enter your password below:


October 18, 2011 Posted by | Security, Shell Script, Tips & Tricks, Unix/Linux | , , , , , , | Enter your password to view comments.

vnStat Commands

# vnstat         -q,      –query          query database

# vnstat         -h,      –hours          show hours

# vnstat         -d,      –days           show days

# vnstat         -m,      –months         show months

# vnstat         -w,      –weeks          show weeks

# vnstat         -t,      –top10          show top10

# vnstat        -s,     –short          use short output

# vnstat        -i,      –iface          select interface (default: eth0)

# vnstat        -?,      –help           short help

# vnstat        -v,      –version        show version

# vnstat        -tr,     –traffic        calculate traffic

# vnstat        -ru,     –rateunit       swap configured rate unit

# vnstat        -l,      –live           show transfer rate in real time

October 17, 2011 Posted by | Tips & Tricks, Unix/Linux | , , , , | Leave a comment

How to monitor bandwidth usage with vnStat PHP based web frontend

You may find it inconvenient to have to login to your server every time you want to see your server’s bandwidth statistics. To make it easier to see bandwidth stats one kind soul made a PHP frontend that uses vnStat to obtain the necessary data and display it with pretty graphs.

vnStat php frontend requires that you have apache, php and the php-gd image processing library installed. Installing the latter is as easy as running the following command as root:

1. Install Apache Web server, php and php-gd

# yum install httpd

# yum install php

# yum install php-gd

2. Download vnStat PHP for Installation

# wget http://www.sqweek.com/sqweek/files/vnstat_php_frontend-1.4.1.tar.gz

# tar -xzf vnstat_php_frontend-1.4.1.tar.gz

3. place it in a web accessible place like /var/www/html

# mkdir /var/www/html/vnstat

# mv vnstat_php_frontend/* /var/www/html/vnstat

4. Edit the config.php file: Just set the correct binary name:

# vi /var/www/html/vnstat/config.php

$vnstat_bin = ‘vnstat’;

October 16, 2011 Posted by | PHP, Tips & Tricks, Unix/Linux | , , , , | Leave a comment

How to configure vnStat for monitoring bandwidth usage

VMSTAT is a tool for those people, having dedicated server hosted somewhere remote at IDC/ISP.

vnStat is a console-based network traffic monitor for Linux that keeps a log of network traffic for the selected interface(s). It uses the network interface statistics provided by the kernel as information source. This means that vnStat won’t actually be sniffing any traffic and also ensures light use of system resources. However, in Linux at least a 2.2 series kernel is required.

* It keeps a log of daily and monthly network traffic for the selected network interface(s).
* It collects all data from /proc file system it means normal user can monitor traffic (no need to run vnstat as a root user)
* Easy to setup & configure
* Ease of use

1. Install vnstat using yum

# yum install vnstat

2. Setup database: Before vnStat can begin logging bandwidth usage you need to tell it to setup the database for your network interface.
Replace eth0 with the correct interface

# vnstat -u -i eth0


-u :forces a database update for interface or creates the database if it doesn’t exist
-i eth0 : use to specify interface

3. Setup correct interface in config file: By default the vnStat cron job will attempt to collect statistics for the eth0 interface.
If your network interface is different from that one you will have to modifiy the /etc/sysconfig/vnstat file:

# vi /etc/sysconfig/vnstat


4. Setup bash alias: Logout of root now and back to your regular user account. If you intend to use vnstat over the command line and
your network interface is not eth0 you should setup a bash alias for ease of use in your .bashrc file:

alias vnstat=”vnstat -i eth3″

5. Statistics by day

# vnstat -d

6. Statistics by Hour

# vmstat -h

7. Statistics By month

# vnstat -m

8. Live monitoring of the network interface

# vnstat -l

9. Display all time top10 traffic days

# vnstat -t

October 15, 2011 Posted by | Tips & Tricks, Unix/Linux | , , , , | Leave a comment