7 Vnstat Command Tips You Need To Learn Now Network Traffic Monitoring Tool

vnstat is a command line network traffic monitoring tool for Linux and Berkeley Software Distribution (BSD). It stores a logs of hourly,daily and monthly network traffic for selected network interfaces. 7 vnstat command tips you need to learn now network traffic monitoring tool.

  • It is easy to install and configure.
  • It can monitor multiple network interfaces at the same time.
  • Vnstat can be used without root permissions.
  • It provides the output summery,hourly,daily,weekly,monthly.
  • It can generate the output in image/png graphically.
  • Low CPU usage regardless of traffic.
  • It uses of network interface statistics provided by the kernel as information source.
  • Months also can be configured to follow billing period.

Installation of vnstat command

Vnstat command install through yum command (or) we can install manualy by download the

command source package

[root@ArkIT-Srv ~]# wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm
--2017-01-26 19:41:01-- http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm
Resolving dl.fedoraproject.org (dl.fedoraproject.org)... 209.132.181.27, 209.132.181.24, 209.132.181.23, ...
Connecting to dl.fedoraproject.org (dl.fedoraproject.org)|209.132.181.27|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 14704 (14K) [application/x-rpm]
Saving to: ‘epel-release-7-9.noarch.rpm’

100%[============================================>] 14,704 53.0KB/s in 0.3s

2017-01-26 19:41:17 (53.0 KB/s) - ‘epel-release-7-9.noarch.rpm’ saved [14704/14704]

[root@ArkIT-Srv ~]# rpm -ivh epel-release-7-9.noarch.rpm

[root@Arkit-Serv ~]# yum install -y vnstat
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
 Installing : vnstat-1.15-2.el7.x86_64 1/1
 Verifying : vnstat-1.15-2.el7.x86_64 1/1

Installed:
 vnstat.x86_64 0:1.15-2.el7

Complete!

(or)

[root@ArkIT-Srv ~]# wget http://humdi.net/vnstat/vnstat-1.13.tar.gz
--2017-01-26 18:46:03-- http://humdi.net/vnstat/vnstat-1.13.tar.gz
Resolving humdi.net (humdi.net)... 213.168.251.41, 2a01:7e00::f03c:91ff:fe37:3421
Connecting to humdi.net (humdi.net)|213.168.251.41|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 101568 (99K) [application/x-gzip]
Saving to: ‘vnstat-1.13.tar.gz’

100%[================================================>] 101,568 326KB/s in 0.3s

2017-01-26 18:46:04 (326 KB/s) - ‘vnstat-1.13.tar.gz’ saved [101568/101568]

[root@ArkIT-Srv ~]# tar -xvf vnstat-1.13.tar.gz
[root@Arkit-Serv ~]# make install

vnstat commnd configuration

If you want find the network interfaces on your system use below command

[root@ArkIT-Srv ~]# vnstat --iflist
Available interfaces: eno16777736 (1000 Mbit) lo

Edit below file for set the interface

[root@Arkit-Serv ~]# vi /etc/sysconfig/vnstat

VNSTAT_OPTIONS="-u -i eth0" <== default interface.

Replace default interface to your system interface.

Enable the vnstat service in RHEL 5 or RHEL 6

[root@Arkit-Serv ~]# chkconfig vnstat on

Start the vnstat service in RHEL 7 / Centos 7

[root@Arkit-Serv ~]# systemctl stop vnstat.service

[root@Arkit-Serv ~]# systemctl restart vnstat.service

[root@ArkIT-Srv ~]# systemctl start vnstat.service
[root@ArkIT-Srv ~]# systemctl status vnstat.service
vnstat.service - vnStat network traffic monitor
 Loaded: loaded (/usr/lib/systemd/system/vnstat.service; disabled)
 Active: active (running) since Thu 2017-01-26 19:49:21 IST; 13s ago
 Docs: man:vnstatd(1)
 man:vnstat(1)
 man:vnstat.conf(5)
 Main PID: 4303 (vnstatd)
 CGroup: /system.slice/vnstat.service
 └─4303 /usr/sbin/vnstatd -n

Create the new database for network traffic monitoring

Now need to create a new database for network traffic monitoring. Force a database update for interface eno16777736 or create the database if it doesn’t exist. This is usually the first command used after a fresh install if the daemon isn’t used.

[root@ArkIT-Srv ~]# vnstat -u -i eno16777736

Vnstat Command options

[root@Arkit-Serv ~]# vnstat --help

vnStat 1.16 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, –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

we can see also complete options list with below command

[root@Arkit-Serv ~]# man vnstat

(or)

[root@Arkit-Serv ~]# vnstat --longhelp
[root@Arkit-Serv ~]# vnstat

Check vnstat version

[root@Arkit-Serv ~]# vnstat -v

Statistics of hourly, daily,monthly 

We can simply fetch the using option -d = Daily, -h Hourly, -m = Monthly

[root@ArkIT-Srv ~]# vnstat -d

 eno16777736 / daily

 day rx | tx | total | avg. rate
 ------------------------+-------------+-------------+---------------
 01/26/2017 7 KiB | 6 KiB | 13 KiB | 0.00 kbit/s
 ------------------------+-------------+-------------+---------------
 estimated -- | -- | -- |
[root@Arkit-Serv ~]# vnstat -h
vnstat command

vnstat command show hours

[root@Arkit-Serv ~]# vnstat -m
eno16777736 / monthly

 month rx | tx | total | avg. rate
 ------------------------+-------------+-------------+---------------
 Jan '17 7 KiB | 6 KiB | 13 KiB | 0.00 kbit/s
 ------------------------+-------------+-------------+---------------
 estimated -- | -- | -- |

Live monitoring

Monitoring Live data is so simply using below command, to come back that interface we have to press CTRL+C key.

[root@ArkIT-Srv ~]# vnstat --live -i eno16777736
Monitoring eno16777736... (press CTRL-C to stop)

 rx: 1 kbit/s 1 p/s tx: 1 kbit/s 0 p/s^C


 eno16777736 / traffic statistics

 rx | tx
--------------------------------------+------------------
 bytes 8 KiB | 18 KiB
--------------------------------------+------------------
 max 1 kbit/s | 1 kbit/s
 average 0.36 kbit/s | 0.80 kbit/s
 min 0 kbit/s | 1 kbit/s
--------------------------------------+------------------
 packets 133 | 99
--------------------------------------+------------------
 max 2 p/s | 1 p/s
 average 0 p/s | 0 p/s
 min 0 p/s | 0 p/s
--------------------------------------+------------------
 time 2.97 minutes

Top 10 statistics

[root@Arkit-Serv ~]# vnstat -t
eno16777736 / top 10

 # day rx | tx | total | avg. rate
 -----------------------------+-------------+-------------+---------------
 no data available
 -----------------------------+-------------+-------------+---------------

[root@ArkIT-Srv ~]# vnstat -tr -i eno16777736
8 packets sampled in 5 seconds
Traffic average for eno16777736

 rx 0.38 kbit/s 0 packets/s
 tx 0.79 kbit/s 0 packets/s

Graphical output

Daily display of stats

[root@Arkit-Serv ~]# vnstati -d -i eth0 -o ~/daily.png
daily vnstat command GUI

daily vnstat command GUI

here “-o” option to specify where the output file will be stored.

Querying Database vnstat command

Database querying using vnstat command

[root@ArkIT-Srv ~]# vnstat -q
Database updated: Thu Jan 26 19:50:52 2017

eno16777736 since 01/26/2017

rx: 7 KiB tx: 6 KiB total: 13 KiB

monthly
 rx | tx | total | avg. rate
 ------------------------+-------------+-------------+---------------
 Jan '17 7 KiB | 6 KiB | 13 KiB | 0.00 kbit/s
 ------------------------+-------------+-------------+---------------
 estimated -- | -- | -- |

daily
 rx | tx | total | avg. rate
 ------------------------+-------------+-------------+---------------
 today 7 KiB | 6 KiB | 13 KiB | 0.00 kbit/s
 ------------------------+-------------+-------------+---------------
 estimated -- | -- | -- |

Monitor Multiple Interfaces

Display traffic summary for a merge of interfaces eth0, eth1 and eth3.

[root@ArkIT-Srv ~]# vnstat -i eth0+eth1+eth3

Output all information about interface eno16777736 in xml format.

[root@ArkIT-Srv ~]# vnstat -i eno16777736 --xml
<vnstat version="1.15" xmlversion="1">
 <interface id="eno16777736">
 <id>eno16777736</id>
 <nick>eno16777736</nick>
 <created><date><year>2017</year><month>01</month><day>26</day></date></created>
 <updated><date><year>2017</year><month>01</month><day>26</day></date><time><hour>20</hour><minute>03</minute></time></updated>
 <traffic>
 <total><rx>51</rx><tx>56</tx></total>
 <days>
 <day id="0"><date><year>2017</year><month>01</month><day>26</day></date><rx>51</rx><tx>56</tx></day>
 </days>
 <months>
 <month id="0"><date><year>2017</year><month>01</month></date><rx>51</rx><tx>56</tx></month>
 </months>
 <tops>
 </tops>
 <hours>
 <hour id="19"><date><year>2017</year><month>01</month><day>26</day></date><rx>7</rx><tx>6</tx></hour>
 <hour id="20"><date><year>2017</year><month>01</month><day>26</day></date><rx>44</rx><tx>50</tx></hour>
 </hours>
 </traffic>
 </interface>
</vnstat>

Output all information of all monitored interfaces in json format.

[root@ArkIT-Srv ~]# vnstat --json
{"vnstatversion":"1.15","jsonversion":"1","interfaces":[{"id":"eno16777736","nick":"eno16777736","created":{"date":{"year":2017,"month":1,"day":26}},"updated":{"date":{"year":2017,"month":1,"day":26},"time":{"hour":20,"minutes":3}},"traffic":{"total":{"rx":51,"tx":56},"days":[{"id":0,"date":{"year":2017,"month":1,"day":26},"rx":51,"tx":56}],"months":[{"id":0,"date":{"year":2017,"month":1},"rx":51,"tx":56}],"tops":[],"hours":[{"id":19,"date":{"year":2017,"month":1,"day":26},"rx":7,"tx":6},{"id":20,"date":{"year":2017,"month":1,"day":26},"rx":44,"tx":50}]}}]}

Give interface eno16777736 the nickname “local”. That information will be later later visible as a label when eno16777736 is queried. The database will also be updated
when this command is executed or created if the database doesn’t exist.

[root@ArkIT-Srv ~]# vnstat -u -i eno16777736 --nick local
[root@ArkIT-Srv ~]# vnstat -q
Database updated: Thu Jan 26 20:26:17 2017

local (eno16777736) since 01/26/2017

rx: 136 KiB tx: 171 KiB total: 307 KiB

monthly
 rx | tx | total | avg. rate
 ------------------------+-------------+-------------+---------------
 Jan '17 136 KiB | 171 KiB | 307 KiB | 0.00 kbit/s
 ------------------------+-------------+-------------+---------------
 estimated -- | -- | -- |

daily
 rx | tx | total | avg. rate
 ------------------------+-------------+-------------+---------------
 today 136 KiB | 171 KiB | 307 KiB | 0.03 kbit/s
 ------------------------+-------------+-------------+---------------
 estimated -- | -- | -- |

Delete Particular Interface Database

[root@ArkITServ ~]vnstat -i eth2 --delete

Delete database of interface eth2 and stop monitoring it.

Related Articles

Linux Performance Monitoring Using vmstat command

10 top command examples

35 amazing server performance monitoring tools

Thanks for your wonderful Support and Encouragement

Stay Connected with us. Learn More and Earn More

ARK

My Name is ARK. Expert in grasping any new technology, Interested in Sharing the knowledge. Learn more & Earn More

You may also like...

Leave a Reply