Install vnStat on CentOS to monitor ECs traffic

Source: Internet
Author: User
Tags vps

Install vnStat on CentOS to monitor ECs traffic

In addition to the Panel provided by the service provider, we can also install vnStat to monitor the upstream and downstream traffic of your VPS or server on a daily basis. The vnStat installation method is simple, which can be divided into compilation and installation or direct installation through the source.

1. Use compilation and Installation

This method is applicable to all Linux releases.

First, download vnStat from the official website:

wget http://humdi.net/vnstat/vnstat-1.11.tar.gz

Decompress:

tar xvzf vnstat-1.11.tar.gz

Enter the directory:

cd vnstat-1.11

Compile and install:

make && make install

If nomakeCommand, you need to installgccAndmake

Under CentOS:

yum -y install gcc make

In Debian/Ubuntu:

sudo apt-get install gcc make

After compilation and installationifconfig -aView your network card, usually as follows:

eth0      Link encap:Ethernet  HWaddr 00:16:3e:a3:c3:9c          inet addr:10.0.0.10  Bcast:10.0.0.63  Mask:255.255.255.192          inet6 addr: fe80::216:3eff:fea3:c39c/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:136503286 errors:0 dropped:189069 overruns:0 frame:0          TX packets:53219265 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000          RX bytes:17989373908 (17.9 GB)  TX bytes:24055536418 (24.0 GB)          Interrupt:32

Then your VPS or server Nic iseth0

Then generate the vnStat database:

/usr/bin/vnstat -u -i eth0

If your Nic is noteth0To change the Network Card Name and/etc/vnstat.confOfInterface "eth0"Your Nic name.

Then you can start vnStat:

vnstatd -d

There is a problem with this method, that is, occasionally the traffic statistics will be stopped, especially in CentOS. When the traffic database is large, bugs will often occur. We recommend that you use the source installation here.

Ii. Use the source to install vnStat

In CentOS, You need to import a third-party EPEL source.

Then install vnStat

yum -y install vnstat

Generate Database

vnstat -u -i eth0

Modify/etc/cron.d/vnstatFile, the last line is changed

*/5 * * * *  root /usr/sbin/vnstat.cron

Set vnStat to run automatically after restart

chkconfig vnstat on

Debian/Ubuntu does not need to import third-party sources.aptInstall:

sudo apt-get install vnstat

Then grant permissions

sudo chmod o+x /usr/bin/vnstat
sudo chmod o+wx /var/lib/vnstat/

Then generate the database

vnstat -u -i eth0

After the installation is complete, you have to like the Debian system. The subsequent actions have been automatically set for you.

Iii. Common vnStat usage

View current real-time traffic

vnstat -l

View daily traffic statistics

vnstat -d

View Monthly Traffic Statistics

vnstat -m

View traffic reports

vnstat

View the real-time traffic of a specific network adapter

vnstat -l -i eth0

In addition, the traffic used does not have much to do with the bandwidth you use. I will open an article separately to illustrate the relationship between traffic and bandwidth.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.