• Contact
  • About Me
  • Privacy Policy
DefenceDev
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos
No Result
View All Result
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos
No Result
View All Result
DefenceDev
No Result
View All Result
ADVERTISEMENT
Home Solutions

Monitor Bandwidth Usage on Linux: Daily and Monthly Statistic

neo by neo
May 27, 2025
in Solutions
0
Monitor Bandwidth Usage on Linux: Daily and Monthly Reports

Monitor Bandwidth Usage on Linux: Daily and Monthly Reports

0
SHARES
25
VIEWS
Share on FacebookShare on Twitter
ADVERTISEMENT

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
vnstast monitoring
vnstast monitoring daily report

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
vnstast monitoring
vnstat monitoring monthly report

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:

ADVERTISEMENT
  • 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

ADVERTISEMENT
chmod +x vnstat_monitor.sh

Run the Script

ADVERTISEMENT
./vnstat_monitor.sh

Output is something like this:

vnstat Script output
vnstat Script output

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
vnstat live bandwidth statistics
vnstat live bandwidth statistics
  • Show top 10 days
vnstat -t
vnstat show top 10 days
vnstat show top 10 days

About The Author

neo

See author's posts

Tags: bash-scriptinglinux
ADVERTISEMENT
Previous Post

Linux Networking: Display Open Ports and Listening Services

Next Post

Fortinet FortiGate: Routing Monitor and Route Attributes

neo

neo

Next Post
Fortinet FortiGate: Routing Monitor and Route Attributes

Fortinet FortiGate: Routing Monitor and Route Attributes

Follow Us

  • Trending
  • Comments
  • Latest
MikroTik: Export Configuration in Text File

MikroTik: Export Configuration in Text File

Fortinet FortiGate: Static Route Configuration via GUI and CLI

Fortinet FortiGate: Static Route Configuration via GUI and CLI

Immich: Installation on Ubuntu 22.04

Immich: Installation on Ubuntu 22.04

Fortinet FortiGate Upgrade Path Tool

Fortinet FortiGate Upgrade Path Tool

NextCloud: Port Forwarding - Essential Ports for Smooth Functionality

NextCloud: Port Forwarding – Essential Ports for Smooth Functionality and Remote Access

Organizing and Managing Photos with Immich: Features I Use

Organizing and Managing Photos with Immich: Features I Use

Install Ubuntu 22.04 on Oracle VM Virtual Box

Install Ubuntu 22.04 on Oracle VM Virtual Box

Linux Directories: cd (Change Directory), pwd (Print Working Directory), mkdir (Make Directory)

Linux Directories: cd (Change Directory), pwd (Print Working Directory), mkdir (Make Directory)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Recent News

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

MikroTik: Check Your Wireless Password

MikroTik: Check Your Wireless Password

ADVERTISEMENT

DefenceDev Tutorials

defencedev Logo

Whether you’re just starting or looking to expand your skills, I hope you find useful information and engaging discussions here. Let me take you through my journey and the goals behind this space!

Follow Us

Browse by Category

  • Blog
  • Cloud
    • Private
  • Linux Tutorials
    • Bash Scripting Tutorials
    • Commands
    • Networking
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Solutions
    • Docker
  • Video Tutorials
    • MikroTik Videos

Recent News

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

  • Site Map
  • Privacy Policy
  • Facebook Page
  • Disclaimer
  • Contact
  • About Me

© 2025 defencedev.com - All rights reserved.

No Result
View All Result
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos

© 2025 defencedev.com - All rights reserved.