Vnstat: Difference between revisions

From Leo's Notes
This page was last edited on 3 January 2022, at 06:12.
Created page with "This vnstat guide is for CentOS/ScientificLinux/RHEL. <syntaxhighlight lang="bash" line start="1" enclose="div"> wget http://humdi.net/vnstat/vnstat-1.11.tar.gz tar -xzf vnst..."
 
m Updated categories
 
(13 intermediate revisions by 2 users not shown)
Line 1: Line 1:
This vnstat guide is for CentOS/ScientificLinux/RHEL.
Vnstat is a command line based network usage monitoring tool. It is capable of showing the current network utilization as well as providing historical data.


<syntaxhighlight lang="bash" line start="1" enclose="div">
== Installation ==
wget http://humdi.net/vnstat/vnstat-1.11.tar.gz
On Red Hat/Fedora based systems, vnstat should be available from the main repository. For older versions of Red Hat such as CentOS 6, it is available from the EPEL repository.
tar -xzf vnstat-1.11.tar.gz
cd vnstat-1.11
make
make install
vnstat --testkernel
/bin/cp examples/init.d/centos/vnstat /etc/init.d/vnstat
ln -s /etc/init.d/vnstat /etc/rc3.d/S40vnstat
vnstat -u -i eth0
/etc/init.d/vnstat start
</syntaxhighlight?


=== Installing from Source ===
The following instructions will set up vnstat from source and should work for CentOS/ScientificLinux/RHEL linux distributions.


[[Category:Guides]]
{{highlight|lang=terminal|code=
# wget http://humdi.net/vnstat/vnstat-1.11.tar.gz
# tar -xzf vnstat-1.11.tar.gz
# cd vnstat-1.11
# make
# make install
# vnstat --testkernel
# /bin/cp examples/init.d/centos/vnstat /etc/init.d/vnstat
# chkconfig --levels 234 --add vnstat
# vnstat -u -i eth0
# /etc/init.d/vnstat start
}}
 
== Configuration ==
Vnstat makes use of a daemon to record network traffic into databases stored in {{code|/var/lib/vnstat}} as well as a cronjob running at 5 minute intervals defined at {{code|/etc/cron.d/vnstat}}.
 
By default, vnstat will only monitor eth0. You will need to adjust the {{code|/etc/sysconfig/vnstat}} and {{code|/etc/vnstat.conf}} configuration files accordingly.
 
You will also need to initialize the interface database by running {{code|vnstat -u -i $InterfaceName}}, otherwise the daemon and cronjob will not record any data.
 
=== Force Update ===
If the cronjob fails for some reason, you may force an update by running:
{{highlight|lang=terminal|code=
# sudo -u /usr/sbin/vnstat.cron --force
}}
 
== Usage ==
Here are some example uses with vnstat.
 
=== Show Live Traffic Statistics ===
To show the live traffic in bytes (rate unit option {{code|-ru 0}})
 
{{highlight|lang=terminal|code=
# vnstat -l -ru 0
(press CTRL-C to stop)
 
  rx:    40.08 MiB/s 28784 p/s          tx:      3.20 MiB/s  9378 p/s^C
 
 
enp3s0  /  traffic statistics
 
                          rx        {{!}}      tx
--------------------------------------+------------------
  bytes                    1.16 GiB  {{!}}      109.45 MiB
--------------------------------------+------------------
          max            49.68 MiB/s  {{!}}      4.58 MiB/s
      average            39.54 MiB/s  {{!}}      3.65 MiB/s
          min            33.13 MiB/s  {{!}}      1.38 MiB/s
--------------------------------------+------------------
  packets                    859772  {{!}}          289093
--------------------------------------+------------------
          max              35996 p/s  {{!}}      12085 p/s
      average              28659 p/s  {{!}}        9636 p/s
          min              24495 p/s  {{!}}        8353 p/s
--------------------------------------+------------------
  time                    30 seconds
}}
 
=== Show Usage by Month ===
{{highlight|lang=terminal|code=
# vnstat -d
}}
 
== Issues ==
=== Not Enough Data ===
You may get the following error if your interface is not being recorded:
{{highlight|lang=text|code=
enp3s0: Not enough data available yet.
}}
 
Ensure that the cronjob and daemon is active and running. Check by running {{code|ps -eaf|grep vnstat}}. There should be at least noe vnstat daemon running.
 
{{Navbox Linux}}
[[Category:Linux]]
[[Category:Linux]]
[[Category:LinuxUtilities]]

Latest revision as of 06:12, 3 January 2022

Vnstat is a command line based network usage monitoring tool. It is capable of showing the current network utilization as well as providing historical data.

Installation

On Red Hat/Fedora based systems, vnstat should be available from the main repository. For older versions of Red Hat such as CentOS 6, it is available from the EPEL repository.

Installing from Source

The following instructions will set up vnstat from source and should work for CentOS/ScientificLinux/RHEL linux distributions.

# wget http://humdi.net/vnstat/vnstat-1.11.tar.gz
# tar -xzf vnstat-1.11.tar.gz
# cd vnstat-1.11
# make
# make install
# vnstat --testkernel
# /bin/cp examples/init.d/centos/vnstat /etc/init.d/vnstat
# chkconfig --levels 234 --add vnstat
# vnstat -u -i eth0
# /etc/init.d/vnstat start

Configuration

Vnstat makes use of a daemon to record network traffic into databases stored in /var/lib/vnstat as well as a cronjob running at 5 minute intervals defined at /etc/cron.d/vnstat.

By default, vnstat will only monitor eth0. You will need to adjust the /etc/sysconfig/vnstat and /etc/vnstat.conf configuration files accordingly.

You will also need to initialize the interface database by running vnstat -u -i $InterfaceName, otherwise the daemon and cronjob will not record any data.

Force Update

If the cronjob fails for some reason, you may force an update by running:

# sudo -u /usr/sbin/vnstat.cron --force

Usage

Here are some example uses with vnstat.

Show Live Traffic Statistics

To show the live traffic in bytes (rate unit option -ru 0)

# vnstat -l -ru 0
(press CTRL-C to stop)

   rx:     40.08 MiB/s 28784 p/s          tx:      3.20 MiB/s  9378 p/s^C


 enp3s0  /  traffic statistics

                           rx         |       tx
--------------------------------------+------------------
  bytes                     1.16 GiB  |      109.45 MiB
--------------------------------------+------------------
          max            49.68 MiB/s  |      4.58 MiB/s
      average            39.54 MiB/s  |      3.65 MiB/s
          min            33.13 MiB/s  |      1.38 MiB/s
--------------------------------------+------------------
  packets                     859772  |          289093
--------------------------------------+------------------
          max              35996 p/s  |       12085 p/s
      average              28659 p/s  |        9636 p/s
          min              24495 p/s  |        8353 p/s
--------------------------------------+------------------
  time                    30 seconds

Show Usage by Month

# vnstat -d

Issues

Not Enough Data

You may get the following error if your interface is not being recorded:

enp3s0: Not enough data available yet.

Ensure that the cronjob and daemon is active and running. Check by running ps -eaf. There should be at least noe vnstat daemon running.