Monitoring bandwidth and traffic

From Pulsed Media Wiki
Revision as of 11:54, 21 April 2025 by Gallogeta (talk | contribs) (Created page with "== Bandwidth and Traffic Monitoring on Debian Servers == Monitoring bandwidth and network traffic is essential for both dedicated servers and virtual private servers (VPS) to...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Bandwidth and Traffic Monitoring on Debian Servers

Monitoring bandwidth and network traffic is essential for both dedicated servers and virtual private servers (VPS) to maintain performance, detect abuse, and track usage trends. Debian-based Linux distributions support a wide variety of tools for this purpose, including command-line utilities and web-based dashboards.

Prerequisites

Before using bandwidth monitoring tools, ensure that the system is up to date and essential packages are installed. Root or sudo access is required.

<syntaxhighlight lang="bash"> sudo apt update && sudo apt install wget curl tar unzip -y </syntaxhighlight>

Tools Overview

Tool Interface Type Features Suitable For
vnStat Command-line Lightweight bandwidth logging by day/month General monitoring
iftop Command-line (real-time) Real-time traffic by connection/IP Live traffic observation
nload Command-line (graphical) Real-time graphical network usage Visual terminal output
bmon Command-line (graphical) Graphs for all interfaces Network debugging
Netdata Web-based dashboard Full system and bandwidth monitoring Beginner-friendly GUI

vnStat

vnStat is a lightweight tool that logs bandwidth usage over time.

<syntaxhighlight lang="bash"> sudo apt install vnstat -y sudo vnstat -u -i eth0 sudo systemctl enable vnstat sudo systemctl start vnstat </syntaxhighlight>

View usage:

<syntaxhighlight lang="bash"> vnstat # Summary vnstat -d # Daily vnstat -m # Monthly vnstat -l # Live traffic </syntaxhighlight>

iftop

iftop displays real-time bandwidth usage by IP and port.

<syntaxhighlight lang="bash"> sudo apt install iftop -y sudo iftop -i eth0 </syntaxhighlight>

Controls: Use arrow keys and keys such as T, P, and S to toggle views. Press Ctrl+C to exit.

nload

nload offers a simple terminal-based graphical view of incoming and outgoing traffic.

<syntaxhighlight lang="bash"> sudo apt install nload -y nload </syntaxhighlight>

bmon

bmon (Bandwidth Monitor) provides graphical interface per network device.

<syntaxhighlight lang="bash"> sudo apt install bmon -y bmon </syntaxhighlight>

Netdata

Netdata is a web-based real-time system and bandwidth monitoring tool.

<syntaxhighlight lang="bash"> bash <(curl -Ss https://my-netdata.io/kickstart.sh) </syntaxhighlight>

Once installed, access via browser:

<syntaxhighlight lang="text"> http://your_server_ip:19999 </syntaxhighlight>

Enable and start:

<syntaxhighlight lang="bash"> sudo systemctl enable netdata sudo systemctl start netdata </syntaxhighlight>

Detecting Network Interfaces

To find the primary network interface:

<syntaxhighlight lang="bash"> ip -brief link show </syntaxhighlight>

Typical interface names:

  • For VPS: eth0, ens3, venet0
  • For dedicated servers: eno1, ens18

Monitoring Per-User Traffic

To view traffic per user or process, install nethogs:

<syntaxhighlight lang="bash"> sudo apt install nethogs -y sudo nethogs eth0 </syntaxhighlight>

Daily Email Report (vnStat)

To receive daily bandwidth reports via email:

1. Install mailutils (if not already installed): <syntaxhighlight lang="bash"> sudo apt install mailutils -y </syntaxhighlight>

2. Add cron job: <syntaxhighlight lang="bash"> sudo crontab -e </syntaxhighlight>

Add the following line:

<syntaxhighlight lang="bash"> 0 1 * * * vnstat -d | mail -s "Daily Bandwidth Report" user@example.com </syntaxhighlight>

Uninstalling Tools

To remove any tool:

<syntaxhighlight lang="bash"> sudo apt remove toolname -y </syntaxhighlight>

Example:

<syntaxhighlight lang="bash"> sudo apt remove vnstat -y </syntaxhighlight>

Summary Table

Tool Command Interface Setup Function
vnStat vnstat vnstat -u -i eth0 Usage logging
iftop iftop -i eth0 Manual Real-time traffic view
nload nload Automatic Graphical bandwidth monitor
bmon bmon Automatic Graphical per-device stats
Netdata Browser access Automatic Full system & bandwidth monitor
nethogs nethogs eth0 Automatic Traffic by user/process