Why Bandwidth Monitoring Matters
Network bandwidth is one of the most critical resources on any Linux server. Whether you are running a web application, database server, or file storage system, understanding your network traffic patterns helps you plan capacity, detect anomalies, and troubleshoot performance issues.
Linux exposes detailed network statistics through the /proc filesystem. The /proc/net/dev file contains cumulative byte and packet counters for every network interface, updated in real-time by the kernel. By reading these counters at intervals, you can calculate throughput, identify saturated links, and detect error conditions.
dargslan-bandwidth-monitor wraps this functionality in a clean Python API and CLI tool, making it easy to integrate bandwidth monitoring into your scripts, dashboards, and alerting systems.
Install dargslan-bandwidth-monitor
pip install dargslan-bandwidth-monitor
Zero dependencies. Reads directly from /proc/net/dev. Works on any Linux system with Python 3.7+.
CLI Usage
# Full bandwidth report
dargslan-bw report
# Interface statistics
dargslan-bw stats
# Real-time throughput test (default 3 seconds)
dargslan-bw speed
# 10-second speed test on specific interface
dargslan-bw speed -i eth0 -d 10
# Total traffic counters
dargslan-bw total
# Check for interface errors and drops
dargslan-bw errors
# JSON output
dargslan-bw json
Python API
from dargslan_bandwidth_monitor import BandwidthMonitor
bm = BandwidthMonitor()
# Current interface statistics
stats = bm.get_stats()
for s in stats:
print(f"{s[\"interface\"]}: RX={s[\"rx_human\"]}, TX={s[\"tx_human\"]}")
# Measure throughput over 5 seconds
throughput = bm.measure_throughput(duration=5)
for t in throughput:
print(f"{t[\"interface\"]}: {t[\"rx_rate_human\"]} down, {t[\"tx_rate_human\"]} up")
# Total traffic across all interfaces
total = bm.get_total_traffic()
print(f"Total traffic: {total[\"total_human\"]}")
# Check for errors
errors = bm.check_errors()
if errors:
print(f"WARNING: {len(errors)} interface issues detected")
Understanding /proc/net/dev
The /proc/net/dev file contains one line per network interface with these fields: interface name, RX bytes, RX packets, RX errors, RX drops, RX fifo, RX frame, RX compressed, RX multicast, TX bytes, TX packets, TX errors, TX drops, TX fifo, TX collisions, TX carrier, TX compressed.
These are cumulative counters that reset only on reboot. To measure throughput, read the counters twice with a known interval between readings and calculate the difference.
Common Alert Thresholds
Set up alerts for these conditions:
- rx_errors > 0 β Check network cable, NIC driver, or switch port
- rx_dropped > 100 β Increase ring buffer size with ethtool
- tx_errors > 0 β Check for duplex mismatch or cable issues
- Interface saturation > 80% β Plan capacity upgrade
Download the Bandwidth Monitoring Cheat Sheet
Get our Network Bandwidth Monitoring Cheat Sheet β covering CLI tools, /proc/net/dev fields, unit conversions, and troubleshooting commands.
Related Tools
See all Python CLI tools for Linux at dargslan.com. Our networking and DevOps eBooks cover bandwidth management, traffic shaping, and network security in depth.