Bandwidth Usage Monitoring on Linux with Periodical Statistic
Monitoring network data usage (monthly, daily or hourly statistic) is crucial for managing bandwidth on Linux servers. Whether you’re managing a home server or a business-critical machine, tracking network traffic helps optimize performance and avoid potential overuse charges. One of the most effective tools for this task is vnStat
, a network traffic monitor that logs and summarizes usage statistics (for example, daily or monthly report can be created with Bash scripts).
In this guide, we’ll show you how to use vnStat
to view network data usage for the last 7 days and the last 3 months. This is useful for both short-term and long-term network monitoring.
What is vnStat?
vnStat
is a lightweight console-based network traffic (bandwidth) monitor that works with Linux systems. It uses data from the /proc
directory and does not require packet capturing, making it resource-efficient. The tool logs the data usage for specified network interfaces and can display reports in various formats, such as daily, weekly, monthly, or even yearly summaries.
You can check manual page for the vnStat application at the link.
You can check project page of vnStat application at the link.
Installing vnStat
To begin using vnStat
, you first need to install it. Most Linux distributions include vnStat
in their package repositories. You can install it using the following commands:
For Debian/Ubuntu-based systems:
sudo apt update
sudo apt install vnstat
After installation, ensure that vnStat
is running as a background service to log data continuously. You can start and enable the service using:
sudo systemctl start vnstat
sudo systemctl enable vnstat
Monitor Data Usage (Bandwidth) on the network for the Last 7 Days (Daily)
Once installed, you can start checking the network usage for the last 7 days – daily report. Run the following command:
vnstat --days 7 --iface eth0

This command outputs the daily data usage for the interface eth0
over the last 7 days. You can replace eth0
with the actual name of your network interface if different.
Monitor Data Usage for the Last 3 Months (Monthly Report)
To get the network traffic report for the last 3 months (monthly report), use the following command:
vnstat --months 3 --iface eth0

This will display a monthly summary of the network usage for the interface eth0
. Like with the daily report, make sure to replace eth0
with your actual network interface.
Understanding vnStat Output
The output of these commands will show you the following information:
- Rx: Total data received.
- Tx: Total data transmitted.
- Total: Combined upload and download data.
- Average: The average data usage for the period.
Crate Monitoring Script for Bandwidth Usage Reporting
Important is to install vnstat!
nano vnstat_monitor.sh
#!/bin/bash
# Check if vnStat is installed
if ! command -v vnstat &> /dev/null
then
echo "vnstat is not installed. Please install vnstat and try again."
exit 1
fi
# Define the network interface
INTERFACE="eth0"
# Define log directory and log file
LOG_DIR="/opt/scripts/log"
LOG_FILE="$LOG_DIR/sysreport_$(date +%F).log"
# Create the log directory if it doesn't exist
mkdir -p $LOG_DIR
# Redirecting both standard output and error output to the log file
{
echo "=========================="
echo " Network Usage Report "
echo "=========================="
echo "Date: $(date)"
echo ""
# Display data usage for the last 7 days
echo "Last 7 Days Data Usage for $INTERFACE:"
vnstat --days 7 --iface $INTERFACE
echo ""
# Display data usage for the last 3 months
echo "Last 3 Months Data Usage for $INTERFACE:"
vnstat --months 3 --iface $INTERFACE
echo ""
echo "Report saved at: $LOG_FILE"
} | tee -a $LOG_FILE
Make the Script Executable
chmod +x vnstat_monitor.sh
Run the Script
./vnstat_monitor.sh
Output is something like this:

For more information about network bandwidth monitoring on Linux see the link.
Other Useful Examples to Generate Different Reports
- Check live Bandwidth usage on interface
vnstat -tr

- Show top 10 days
vnstat -t
