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 nomake
Command, you need to installgcc
Andmake
Under CentOS:
yum -y install gcc make
In Debian/Ubuntu:
sudo apt-get install gcc make
After compilation and installationifconfig -a
View 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 noteth0
To change the Network Card Name and/etc/vnstat.conf
OfInterface "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/vnstat
File, 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.apt
Install:
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.