How to install and use vnstat in Centos

Source: Internet
Author: User
Tags centos

1. Install vnstat

The epel package comes with vnstat. You can install epel and run the following command:

Yum install vnstat-y
II. Configuration

Modify the/etc/sysconfig/vnstat file and you can see the following configuration (if the default network port is eth0, you can not modify it ):

VNSTAT_OPTIONS = "-u-I eth0"
Modify/etc/vnstat. conf and focus on "Interface" to confirm the default network port.

Interface "eth0"
For ease of viewing, I modified the following parameters
RateUnit 0
3. Create a database

Before creating a database file, run the chsh command to modify the vnstat execution script.

# Chsh-s/bin/bash vnstat
Run the following command to create a database:

# Runuser-l vnstat-g vnstat-c '/usr/bin/vnstat-u-I eth0'
When you create a database for the first time, the following content appears:

Error: Unable to read database "/var/lib/vnstat/eth0 ".
Info:-> A new database has been created.
If you directly execute runuser to create a database without modifying the shell environment of vnstat, the following error is reported:

This account is currently not available.
After the database is successfully created, the shell environment of vnstat is restored to nologin.

# Chsh-s/sbin/nologin vnstat
Run vnstat after creation. An error is returned due to insufficient data volume:

Eth0: Not enough data available yet.
After waiting for a while, you can output the result:

[Root @ li815-118 ~] # Vnstat
Database updated: Wed Jan 21 22:45:02 2015

Eth0 since 01/21/15

Rx: 521.74 MB tx: 581.62 MB total: 1.08 GB

Monthly
Rx | tx | total | avg. rate
------------------------ + ------------- + ---------------
Jan '15 521.74 MB | 581.62 MB | 1.08 GB | 0.62 KB/s
------------------------ + ------------- + ---------------
Estimated 771 MB | 859 MB | 1.59 GB |

Daily
Rx | tx | total | avg. rate
------------------------ + ------------- + ---------------
Today 521.74 MB | 581.62 MB | 1.08 GB | 13.80 KB/s
------------------------ + ------------- + ---------------
Estimated 549 MB | 612 MB | 1.13 GB |
4. Boot Service

The vnstat service is automatically started when centos6 is started:

Chkconfig vnstat on
Some service control commands of vnstat:

Service vnstat start
Service vnstat stop
Service vnstat restart
Service vnstat status
V. Example

Output xml format data

Vnstat-I eth0-xml
View eth0 status

Vnstat-I eth0
View daily status

Vnstat-I eth0-d
View the status of each hour

Vnstat-I eth0-h
View Weekly Status

Vnstat-I eth0-w
View Top 10 networks

Vnstat-I eth0-t
View information in simple mode

Vnstat-I eth0-s
Computing transmission

Vnstat-I eth0-tr
View real-time rate

Vnstat-I eth0-l

Related Article

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.