Bandwidth Monitoring Over Time: Complete Admin Guide

Master network bandwidth monitoring with comprehensive tools, techniques, and methodologies for tracking traffic patterns and optimizing performance.

Bandwidth Monitoring Over Time: Comprehensive Guide

Introduction

Bandwidth monitoring is a critical aspect of network administration that involves tracking and analyzing network traffic patterns over extended periods. This practice enables administrators to understand network utilization trends, identify bottlenecks, plan capacity upgrades, and troubleshoot performance issues effectively.

Monitoring bandwidth usage over time provides insights into network behavior patterns, peak usage periods, and helps in making informed decisions about network infrastructure investments. This comprehensive guide covers various tools, techniques, and methodologies for implementing effective bandwidth monitoring solutions.

Fundamental Concepts

What is Bandwidth Monitoring

Bandwidth monitoring refers to the continuous measurement and recording of data transmission rates across network interfaces. It involves collecting metrics such as:

- Ingress Traffic: Data flowing into a network interface - Egress Traffic: Data flowing out of a network interface - Utilization Percentage: The ratio of used bandwidth to available bandwidth - Packet Rates: Number of packets transmitted per second - Error Rates: Frequency of transmission errors

Key Metrics and Terminology

| Metric | Description | Unit | Purpose | |--------|-------------|------|---------| | Throughput | Actual data transfer rate | bps, Mbps, Gbps | Measure real performance | | Utilization | Percentage of bandwidth used | Percentage | Identify congestion | | Latency | Time for data to travel | Milliseconds | Quality assessment | | Jitter | Variation in latency | Milliseconds | Stability measurement | | Packet Loss | Dropped packets ratio | Percentage | Reliability indicator | | Peak Usage | Maximum recorded bandwidth | bps, Mbps, Gbps | Capacity planning |

Monitoring Methodologies

SNMP-Based Monitoring

Simple Network Management Protocol (SNMP) is the most widely used method for bandwidth monitoring. It allows centralized collection of network statistics from managed devices.

SNMP Architecture Components: - SNMP Manager: Central monitoring system - SNMP Agent: Software running on monitored devices - Management Information Base (MIB): Database of manageable objects

Key SNMP OIDs for Bandwidth Monitoring:

| OID | Description | Data Type | |-----|-------------|-----------| | 1.3.6.1.2.1.2.2.1.10 | ifInOctets | Counter32 | | 1.3.6.1.2.1.2.2.1.16 | ifOutOctets | Counter32 | | 1.3.6.1.2.1.2.2.1.5 | ifSpeed | Gauge32 | | 1.3.6.1.2.1.2.2.1.8 | ifOperStatus | Integer |

Flow-Based Monitoring

Flow-based monitoring analyzes network traffic by examining flow records generated by network devices. Popular flow protocols include:

- NetFlow: Cisco proprietary protocol - sFlow: Industry standard sampling protocol - IPFIX: Internet Protocol Flow Information Export

Flow Record Components: - Source and destination IP addresses - Source and destination port numbers - Protocol type - Type of Service (ToS) - Input interface - Packet and byte counts - Flow timestamps

Packet Capture Monitoring

Deep packet inspection involves capturing and analyzing individual network packets to provide detailed traffic analysis.

Advantages: - Complete traffic visibility - Application-level analysis - Security threat detection - Performance troubleshooting

Limitations: - High storage requirements - Processing overhead - Privacy concerns - Scalability challenges

Command Line Tools for Bandwidth Monitoring

iftop Command

The iftop command provides real-time bandwidth usage display for network interfaces.

Basic Syntax: `bash iftop [options] `

Common Options:

| Option | Description | Example | |--------|-------------|---------| | -i | Specify interface | iftop -i eth0 | | -n | Disable hostname resolution | iftop -n | | -P | Show port numbers | iftop -P | | -p | Run in promiscuous mode | iftop -p | | -B | Display bandwidth in bytes | iftop -B |

Example Usage: `bash

Monitor specific interface with port numbers

iftop -i eth0 -P

Monitor without DNS resolution in bytes

iftop -n -B

Monitor with promiscuous mode

sudo iftop -p -i wlan0 `

Output Interpretation: - Left column shows source addresses - Right column shows destination addresses - Three columns on right show average bandwidth over 2s, 10s, and 40s intervals - Bottom section shows cumulative statistics

nload Command

The nload command displays network traffic and bandwidth usage in real-time with graphical representation.

Basic Syntax: `bash nload [options] [interface] `

Key Features: - Graphical bandwidth display - Multiple interface monitoring - Configurable refresh intervals - Traffic statistics

Command Examples: `bash

Monitor default interface

nload

Monitor specific interface

nload eth0

Monitor multiple interfaces

nload eth0 eth1

Set refresh interval to 500ms

nload -t 500

Monitor with specific unit (k=KB/s, m=MB/s, g=GB/s)

nload -u k `

Configuration Options:

| Option | Description | Default | |--------|-------------|---------| | -t | Refresh interval (ms) | 500 | | -u | Unit (h,b,k,m,g) | k | | -U | Unit for total (H,B,K,M,G) | M | | -a | Average calculation period | 300s |

vnstat Command

The vnstat command provides network traffic statistics with historical data storage capabilities.

Installation and Setup: `bash

Install vnstat

sudo apt-get install vnstat

Initialize database for interface

sudo vnstat -u -i eth0

Start vnstat daemon

sudo systemctl start vnstat sudo systemctl enable vnstat `

Basic Usage Examples: `bash

Show statistics for default interface

vnstat

Show statistics for specific interface

vnstat -i eth0

Show hourly statistics

vnstat -h

Show daily statistics

vnstat -d

Show monthly statistics

vnstat -m

Show top 10 days

vnstat -t

Show live statistics (similar to top)

vnstat -l `

Advanced vnstat Commands:

| Command | Description | Output Format | |---------|-------------|---------------| | vnstat -w | Weekly statistics | Week-by-week breakdown | | vnstat -y | Yearly statistics | Annual summaries | | vnstat --json | JSON output | Machine-readable format | | vnstat --xml | XML output | Structured data format | | vnstat -tr | Traffic rate | Real-time rate display |

nethogs Command

The nethogs command monitors bandwidth usage per process, providing application-level visibility.

Installation: `bash

Ubuntu/Debian

sudo apt-get install nethogs

CentOS/RHEL

sudo yum install nethogs `

Usage Examples: `bash

Monitor default interface

sudo nethogs

Monitor specific interface

sudo nethogs eth0

Monitor multiple interfaces

sudo nethogs eth0 eth1

Set refresh delay (seconds)

sudo nethogs -d 5

Monitor specific process

sudo nethogs -p PID `

Interactive Commands within nethogs:

| Key | Action | Description | |-----|--------|-------------| | q | Quit | Exit nethogs | | s | Sort by sent | Sort by upload traffic | | r | Sort by received | Sort by download traffic | | m | Change units | Cycle through KB/s, MB/s, etc. |

bmon Command

The bmon command provides detailed bandwidth monitoring with multiple output formats and interfaces.

Installation and Basic Usage: `bash

Install bmon

sudo apt-get install bmon

Basic monitoring

bmon

Monitor specific interface

bmon -p eth0

Output to file

bmon -o format:fmt=csv > bandwidth.csv

Set update interval

bmon -r 2 `

Output Format Options:

| Format | Description | Command Example | |--------|-------------|-----------------| | curses | Interactive display | bmon -o curses | | ascii | Text output | bmon -o ascii | | csv | Comma-separated values | bmon -o csv | | format | Custom format | bmon -o format:fmt=csv |

Advanced Monitoring Tools

Cacti - Web-Based Network Monitoring

Cacti is a comprehensive network monitoring solution that uses RRDTool for data storage and graphing.

Key Features: - Web-based interface - SNMP polling - Customizable graphs - Template system - User management - Plugin architecture

Installation Process: `bash

Install required packages

sudo apt-get update sudo apt-get install apache2 mysql-server php php-mysql php-snmp snmp snmp-mibs-downloader rrdtool

Download and install Cacti

wget https://www.cacti.net/downloads/cacti-latest.tar.gz tar -xzf cacti-latest.tar.gz sudo mv cacti-* /var/www/html/cacti

Set permissions

sudo chown -R www-data:www-data /var/www/html/cacti sudo chmod -R 755 /var/www/html/cacti `

Configuration Steps:

| Step | Description | Configuration File | |------|-------------|-------------------| | 1 | Database setup | MySQL configuration | | 2 | Web server config | Apache virtual host | | 3 | PHP settings | php.ini modifications | | 4 | Cron job setup | Poller scheduling | | 5 | SNMP configuration | Community strings |

LibreNMS - Open Source Monitoring

LibreNMS provides autodiscovery, alerting, and extensive device support for network monitoring.

Installation via Script: `bash

Download and run installation script

cd /opt sudo git clone https://github.com/librenms/librenms.git cd librenms sudo ./scripts/install.sh `

Key Configuration Files:

| File | Purpose | Location | |------|---------|----------| | config.php | Main configuration | /opt/librenms/config.php | | .env | Environment variables | /opt/librenms/.env | | snmpd.conf | SNMP daemon config | /etc/snmp/snmpd.conf |

Nagios Network Monitoring

Nagios provides comprehensive infrastructure monitoring with alerting capabilities.

Core Components: - Nagios Core: Main monitoring engine - Nagios Plugins: Check scripts and programs - NRPE: Remote plugin executor - NSCA: Passive check result acceptor

Bandwidth Monitoring Plugin Example: `bash #!/bin/bash

check_bandwidth.sh - Custom bandwidth check plugin

INTERFACE=$1 WARNING=$2 CRITICAL=$3

Get current bandwidth utilization

UTILIZATION=$(snmpwalk -v2c -c public localhost 1.3.6.1.2.1.2.2.1.10.$INTERFACE | awk '{print $4}')

if [ $UTILIZATION -gt $CRITICAL ]; then echo "CRITICAL - Bandwidth utilization: ${UTILIZATION}%" exit 2 elif [ $UTILIZATION -gt $WARNING ]; then echo "WARNING - Bandwidth utilization: ${UTILIZATION}%" exit 1 else echo "OK - Bandwidth utilization: ${UTILIZATION}%" exit 0 fi `

Data Collection and Storage

RRDTool (Round Robin Database Tool)

RRDTool is specifically designed for time-series data storage and is widely used for network monitoring applications.

Creating RRD Database: `bash

Create RRD database for bandwidth monitoring

rrdtool create bandwidth.rrd \ --start now-1d \ --step 300 \ DS:input:COUNTER:600:0:1250000000 \ DS:output:COUNTER:600:0:1250000000 \ RRA:AVERAGE:0.5:1:288 \ RRA:AVERAGE:0.5:12:168 \ RRA:AVERAGE:0.5:288:31 \ RRA:MAX:0.5:1:288 \ RRA:MAX:0.5:12:168 \ RRA:MAX:0.5:288:31 `

Data Source Parameters:

| Parameter | Description | Example Value | |-----------|-------------|---------------| | DS Name | Data source identifier | input, output | | Type | Data source type | COUNTER, GAUGE | | Heartbeat | Maximum seconds between updates | 600 | | Min/Max | Value range limits | 0:1250000000 |

Round Robin Archive (RRA) Configuration:

| Archive Type | Consolidation | Steps | Rows | Time Span | |--------------|---------------|--------|------|-----------| | AVERAGE | 0.5 | 1 | 288 | 24 hours (5min resolution) | | AVERAGE | 0.5 | 12 | 168 | 1 week (1hour resolution) | | AVERAGE | 0.5 | 288 | 31 | 1 month (1day resolution) |

Updating RRD Database: `bash

Update with current values

rrdtool update bandwidth.rrd N:1234567890:987654321

Update with timestamp

rrdtool update bandwidth.rrd 1609459200:1234567890:987654321 `

Generating Graphs: `bash

Create bandwidth graph

rrdtool graph bandwidth_daily.png \ --start -1d \ --title "Daily Bandwidth Usage" \ --vertical-label "Bits per Second" \ --width 800 \ --height 400 \ DEF:input=bandwidth.rrd:input:AVERAGE \ DEF:output=bandwidth.rrd:output:AVERAGE \ CDEF:input_bits=input,8,* \ CDEF:output_bits=output,8,* \ LINE1:input_bits#00FF00:"Input Traffic" \ LINE1:output_bits#0000FF:"Output Traffic" \ GPRINT:input_bits:LAST:"Current Input\: %5.2lf %sbps" \ GPRINT:output_bits:LAST:"Current Output\: %5.2lf %sbps" `

InfluxDB Time Series Database

InfluxDB is a modern time-series database optimized for high-write and query loads typical in monitoring applications.

Installation and Setup: `bash

Install InfluxDB

wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add - echo "deb https://repos.influxdata.com/ubuntu bionic stable" | sudo tee /etc/apt/sources.list.d/influxdb.list sudo apt-get update && sudo apt-get install influxdb

Start InfluxDB service

sudo systemctl start influxdb sudo systemctl enable influxdb `

Database Schema Design: `sql -- Create database CREATE DATABASE network_monitoring

-- Create retention policies CREATE RETENTION POLICY "realtime" ON "network_monitoring" DURATION 24h REPLICATION 1 DEFAULT CREATE RETENTION POLICY "daily" ON "network_monitoring" DURATION 30d REPLICATION 1 CREATE RETENTION POLICY "monthly" ON "network_monitoring" DURATION 365d REPLICATION 1

-- Example data structure -- Measurement: bandwidth -- Tags: interface, host, direction -- Fields: bytes, packets, utilization -- Timestamp: automatic `

Data Insertion Example: `bash

Using InfluxDB Line Protocol

curl -i -XPOST 'http://localhost:8086/write?db=network_monitoring' \ --data-binary 'bandwidth,host=router1,interface=eth0,direction=in bytes=1234567890,packets=987654,utilization=45.2' `

Prometheus and Grafana Stack

Prometheus provides metrics collection and alerting, while Grafana offers visualization capabilities.

Prometheus Configuration (prometheus.yml): `yaml global: scrape_interval: 15s evaluation_interval: 15s

rule_files: - "bandwidth_rules.yml"

scrape_configs: - job_name: 'snmp-bandwidth' static_configs: - targets: ['192.168.1.1:161'] metrics_path: /snmp params: module: [if_mib] relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: 127.0.0.1:9116 `

SNMP Exporter Configuration: `yaml

snmp.yml

modules: if_mib: walk: - 1.3.6.1.2.1.2.2.1.10 # ifInOctets - 1.3.6.1.2.1.2.2.1.16 # ifOutOctets - 1.3.6.1.2.1.2.2.1.5 # ifSpeed metrics: - name: ifInOctets oid: 1.3.6.1.2.1.2.2.1.10 type: counter help: Input octets on interface - name: ifOutOctets oid: 1.3.6.1.2.1.2.2.1.16 type: counter help: Output octets on interface `

Scripting and Automation

Bash Script for Bandwidth Monitoring

Comprehensive Monitoring Script: `bash #!/bin/bash

bandwidth_monitor.sh - Comprehensive bandwidth monitoring script

Configuration

INTERFACE="eth0" LOG_FILE="/var/log/bandwidth_monitor.log" ALERT_THRESHOLD=80 EMAIL_RECIPIENT="admin@company.com" SNMP_COMMUNITY="public" SNMP_HOST="localhost"

Function to get interface statistics

get_interface_stats() { local interface=$1 local stats_file="/proc/net/dev" if [ -f "$stats_file" ]; then grep "$interface:" "$stats_file" | awk '{print $2, $10}' else echo "0 0" fi }

Function to calculate bandwidth utilization

calculate_utilization() { local current_bytes=$1 local previous_bytes=$2 local time_diff=$3 local interface_speed=$4 local bytes_diff=$((current_bytes - previous_bytes)) local bits_per_second=$((bytes_diff * 8 / time_diff)) local utilization=$((bits_per_second * 100 / interface_speed)) echo $utilization }

Function to send alert

send_alert() { local message=$1 local timestamp=$(date '+%Y-%m-%d %H:%M:%S') echo "[$timestamp] ALERT: $message" >> "$LOG_FILE" echo "$message" | mail -s "Bandwidth Alert" "$EMAIL_RECIPIENT" }

Function to log statistics

log_stats() { local timestamp=$1 local interface=$2 local in_bytes=$3 local out_bytes=$4 local in_util=$5 local out_util=$6 echo "[$timestamp] $interface IN: ${in_bytes} bytes (${in_util}%) OUT: ${out_bytes} bytes (${out_util}%)" >> "$LOG_FILE" }

Main monitoring loop

main() { local previous_in=0 local previous_out=0 local previous_time=$(date +%s) # Get interface speed (assuming 1Gbps) local interface_speed=1000000000 while true; do sleep 60 # Monitor every minute local current_time=$(date +%s) local time_diff=$((current_time - previous_time)) local timestamp=$(date '+%Y-%m-%d %H:%M:%S') # Get current statistics local stats=($(get_interface_stats "$INTERFACE")) local current_in=${stats[0]} local current_out=${stats[1]} if [ $previous_in -gt 0 ]; then # Calculate utilization local in_util=$(calculate_utilization "$current_in" "$previous_in" "$time_diff" "$interface_speed") local out_util=$(calculate_utilization "$current_out" "$previous_out" "$time_diff" "$interface_speed") # Log statistics log_stats "$timestamp" "$INTERFACE" "$current_in" "$current_out" "$in_util" "$out_util" # Check for alerts if [ $in_util -gt $ALERT_THRESHOLD ]; then send_alert "High inbound utilization on $INTERFACE: ${in_util}%" fi if [ $out_util -gt $ALERT_THRESHOLD ]; then send_alert "High outbound utilization on $INTERFACE: ${out_util}%" fi fi # Update previous values previous_in=$current_in previous_out=$current_out previous_time=$current_time done }

Script execution

case "$1" in start) echo "Starting bandwidth monitoring..." main & echo $! > /var/run/bandwidth_monitor.pid ;; stop) echo "Stopping bandwidth monitoring..." if [ -f /var/run/bandwidth_monitor.pid ]; then kill $(cat /var/run/bandwidth_monitor.pid) rm /var/run/bandwidth_monitor.pid fi ;; status) if [ -f /var/run/bandwidth_monitor.pid ]; then echo "Bandwidth monitoring is running (PID: $(cat /var/run/bandwidth_monitor.pid))" else echo "Bandwidth monitoring is not running" fi ;; *) echo "Usage: $0 {start|stop|status}" exit 1 ;; esac `

Python Script with SNMP Integration

Advanced Python Monitoring Script: `python #!/usr/bin/env python3 """ Advanced Bandwidth Monitor with SNMP Support Monitors network interfaces and stores data in various formats """

import time import json import sqlite3 import smtplib from datetime import datetime from pysnmp.hlapi import * from email.mime.text import MIMEText import argparse import logging

class BandwidthMonitor: def __init__(self, config_file): self.config = self.load_config(config_file) self.setup_logging() self.setup_database() def load_config(self, config_file): """Load configuration from JSON file""" with open(config_file, 'r') as f: return json.load(f) def setup_logging(self): """Setup logging configuration""" logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', handlers=[ logging.FileHandler(self.config['log_file']), logging.StreamHandler() ] ) self.logger = logging.getLogger(__name__) def setup_database(self): """Initialize SQLite database for storing bandwidth data""" self.conn = sqlite3.connect(self.config['database_file']) cursor = self.conn.cursor() cursor.execute(''' CREATE TABLE IF NOT EXISTS bandwidth_data ( id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp DATETIME, host VARCHAR(255), interface VARCHAR(50), in_octets BIGINT, out_octets BIGINT, in_utilization FLOAT, out_utilization FLOAT ) ''') cursor.execute(''' CREATE INDEX IF NOT EXISTS idx_timestamp_host ON bandwidth_data(timestamp, host) ''') self.conn.commit() def snmp_walk(self, host, community, oid): """Perform SNMP walk to get interface data""" results = {} for (errorIndication, errorStatus, errorIndex, varBinds) in nextCmd( SnmpEngine(), CommunityData(community), UdpTransportTarget((host, 161)), ContextData(), ObjectType(ObjectIdentity(oid)), lexicographicMode=False): if errorIndication: self.logger.error(f"SNMP Error: {errorIndication}") break elif errorStatus: self.logger.error(f"SNMP Error: {errorStatus.prettyPrint()}") break else: for varBind in varBinds: oid_str = varBind[0].prettyPrint() value = int(varBind[1]) interface_index = oid_str.split('.')[-1] results[interface_index] = value return results def get_interface_speeds(self, host, community): """Get interface speeds via SNMP""" return self.snmp_walk(host, community, '1.3.6.1.2.1.2.2.1.5') def get_interface_names(self, host, community): """Get interface names via SNMP""" results = {} for (errorIndication, errorStatus, errorIndex, varBinds) in nextCmd( SnmpEngine(), CommunityData(community), UdpTransportTarget((host, 161)), ContextData(), ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2.1.2')), lexicographicMode=False): if errorIndication or errorStatus: break else: for varBind in varBinds: oid_str = varBind[0].prettyPrint() value = varBind[1].prettyPrint() interface_index = oid_str.split('.')[-1] results[interface_index] = value return results def monitor_host(self, host_config): """Monitor a single host""" host = host_config['host'] community = host_config['community'] self.logger.info(f"Monitoring host: {host}") # Get interface information interface_names = self.get_interface_names(host, community) interface_speeds = self.get_interface_speeds(host, community) # Get current counters in_octets = self.snmp_walk(host, community, '1.3.6.1.2.1.2.2.1.10') out_octets = self.snmp_walk(host, community, '1.3.6.1.2.2.1.16') # Store data timestamp = datetime.now() cursor = self.conn.cursor() for interface_index in in_octets.keys(): if interface_index in interface_names: interface_name = interface_names[interface_index] interface_speed = interface_speeds.get(interface_index, 0) cursor.execute(''' INSERT INTO bandwidth_data (timestamp, host, interface, in_octets, out_octets, in_utilization, out_utilization) VALUES (?, ?, ?, ?, ?, ?, ?) ''', ( timestamp, host, interface_name, in_octets[interface_index], out_octets[interface_index], 0, # Utilization calculated later 0 # Utilization calculated later )) self.conn.commit() def calculate_utilization(self, host, interface, current_time): """Calculate bandwidth utilization based on historical data""" cursor = self.conn.cursor() # Get last two data points cursor.execute(''' SELECT timestamp, in_octets, out_octets FROM bandwidth_data WHERE host = ? AND interface = ? ORDER BY timestamp DESC LIMIT 2 ''', (host, interface)) results = cursor.fetchall() if len(results) < 2: return 0, 0 # Calculate time difference in seconds time_diff = (datetime.fromisoformat(results[0][0]) - datetime.fromisoformat(results[1][0])).total_seconds() if time_diff <= 0: return 0, 0 # Calculate byte differences in_diff = results[0][1] - results[1][1] out_diff = results[0][2] - results[1][2] # Convert to bits per second in_bps = (in_diff * 8) / time_diff out_bps = (out_diff * 8) / time_diff # Get interface speed interface_speed = self.get_interface_speed(host, interface) if interface_speed > 0: in_util = (in_bps / interface_speed) * 100 out_util = (out_bps / interface_speed) * 100 else: in_util = out_util = 0 return in_util, out_util def send_alert(self, subject, message): """Send email alert""" if not self.config.get('email_enabled', False): return smtp_config = self.config['smtp'] msg = MIMEText(message) msg['Subject'] = subject msg['From'] = smtp_config['from'] msg['To'] = smtp_config['to'] try: server = smtplib.SMTP(smtp_config['server'], smtp_config['port']) if smtp_config.get('use_tls', False): server.starttls() if smtp_config.get('username'): server.login(smtp_config['username'], smtp_config['password']) server.send_message(msg) server.quit() self.logger.info(f"Alert sent: {subject}") except Exception as e: self.logger.error(f"Failed to send alert: {e}") def run(self): """Main monitoring loop""" self.logger.info("Starting bandwidth monitoring") while True: try: for host_config in self.config['hosts']: self.monitor_host(host_config) # Sleep for configured interval time.sleep(self.config.get('interval', 300)) except KeyboardInterrupt: self.logger.info("Monitoring stopped by user") break except Exception as e: self.logger.error(f"Monitoring error: {e}") time.sleep(60) # Wait before retrying self.conn.close()

def main(): parser = argparse.ArgumentParser(description='Advanced Bandwidth Monitor') parser.add_argument('--config', required=True, help='Configuration file path') args = parser.parse_args() monitor = BandwidthMonitor(args.config) monitor.run()

if __name__ == '__main__': main() `

Analysis and Reporting

Historical Data Analysis

Bandwidth Trend Analysis Queries: `sql -- Daily bandwidth summary SELECT DATE(timestamp) as date, host, interface, AVG(in_utilization) as avg_in_util, MAX(in_utilization) as peak_in_util, AVG(out_utilization) as avg_out_util, MAX(out_utilization) as peak_out_util FROM bandwidth_data WHERE timestamp >= datetime('now', '-30 days') GROUP BY DATE(timestamp), host, interface ORDER BY date DESC;

-- Peak usage hours identification SELECT strftime('%H', timestamp) as hour, AVG(in_utilization + out_utilization) as avg_total_util FROM bandwidth_data WHERE timestamp >= datetime('now', '-7 days') GROUP BY strftime('%H', timestamp) ORDER BY avg_total_util DESC;

-- Interface capacity planning SELECT host, interface, MAX(in_utilization) as peak_in, MAX(out_utilization) as peak_out, AVG(in_utilization) as avg_in, AVG(out_utilization) as avg_out, COUNT(*) as samples FROM bandwidth_data WHERE timestamp >= datetime('now', '-90 days') GROUP BY host, interface HAVING peak_in > 70 OR peak_out > 70 ORDER BY peak_in DESC; `

Automated Report Generation

Weekly Bandwidth Report Script: `bash #!/bin/bash

weekly_bandwidth_report.sh

REPORT_DIR="/var/reports/bandwidth" REPORT_DATE=$(date '+%Y-%m-%d') REPORT_FILE="$REPORT_DIR/bandwidth_report_$REPORT_DATE.html"

Create report directory

mkdir -p "$REPORT_DIR"

Generate HTML report

cat > "$REPORT_FILE" << EOF

Weekly Bandwidth Report

Report Period: $(date -d '7 days ago' '+%Y-%m-%d') to $REPORT_DATE

Top Utilized Interfaces

EOF

Add data rows (this would typically query your database)

sqlite3 -html /var/db/bandwidth.db " SELECT host, interface, printf('%.2f', MAX(in_utilization)) as peak_in, printf('%.2f', MAX(out_utilization)) as peak_out, printf('%.2f', AVG(in_utilization)) as avg_in, printf('%.2f', AVG(out_utilization)) as avg_out FROM bandwidth_data WHERE timestamp >= datetime('now', '-7 days') GROUP BY host, interface ORDER BY MAX(in_utilization) DESC LIMIT 20; " >> "$REPORT_FILE"

cat >> "$REPORT_FILE" << EOF

Host Interface Peak Inbound (%) Peak Outbound (%) Average Inbound (%) Average Outbound (%)

Bandwidth Growth Trends

Analysis of bandwidth growth over the past 4 weeks...

Capacity Planning Recommendations

  • Interfaces exceeding 80% utilization require immediate attention
  • Interfaces exceeding 70% utilization should be monitored closely
  • Consider upgrading interfaces with consistent high utilization

Report generated on: $(date)

EOF

echo "Report generated: $REPORT_FILE"

Email report if configured

if [ -n "$EMAIL_RECIPIENT" ]; then mail -s "Weekly Bandwidth Report - $REPORT_DATE" -a "Content-Type: text/html" "$EMAIL_RECIPIENT" < "$REPORT_FILE" fi `

Best Practices and Optimization

Monitoring Strategy

Effective Bandwidth Monitoring Principles:

| Principle | Description | Implementation | |-----------|-------------|----------------| | Baseline Establishment | Document normal usage patterns | Collect 30 days of data minimum | | Threshold Setting | Define meaningful alert levels | 70% warning, 85% critical | | Trend Analysis | Monitor growth patterns | Weekly/monthly comparisons | | Capacity Planning | Proactive infrastructure scaling | 18-month growth projections | | Documentation | Maintain monitoring procedures | Standard operating procedures |

Performance Optimization

Database Optimization Strategies: `sql -- Create appropriate indexes CREATE INDEX idx_bandwidth_timestamp ON bandwidth_data(timestamp); CREATE INDEX idx_bandwidth_host_interface ON bandwidth_data(host, interface); CREATE INDEX idx_bandwidth_utilization ON bandwidth_data(in_utilization, out_utilization);

-- Implement data retention policy DELETE FROM bandwidth_data WHERE timestamp < datetime('now', '-365 days');

-- Archive old data CREATE TABLE bandwidth_data_archive AS SELECT * FROM bandwidth_data WHERE timestamp < datetime('now', '-90 days'); `

Monitoring Efficiency Guidelines:

| Aspect | Recommendation | Rationale | |--------|----------------|-----------| | Polling Interval | 5 minutes for normal monitoring | Balance between accuracy and load | | Data Retention | 1 year detailed, 5 years summarized | Compliance and trend analysis | | Alert Frequency | Maximum 1 per hour per condition | Prevent alert fatigue | | Graph Resolution | Multiple time scales available | Different analysis needs | | Storage Compression | Use appropriate data types | Optimize storage usage |

Security Considerations

SNMP Security Best Practices: - Use SNMPv3 with authentication and encryption - Implement access control lists (ACLs) - Change default community strings - Monitor SNMP access attempts - Regular security audits

Network Monitoring Security: `bash

SNMPv3 configuration example

snmpwalk -v3 -u monitor_user -l authPriv \ -a SHA -A "auth_password" \ -x AES -X "priv_password" \ 192.168.1.1 1.3.6.1.2.1.2.2.1.10 `

This comprehensive guide provides the foundation for implementing effective bandwidth monitoring solutions that scale with organizational needs while maintaining security and performance standards. The combination of command-line tools, scripting automation, and proper data management creates a robust monitoring infrastructure capable of supporting proactive network management and capacity planning initiatives.

Tags

  • Performance Optimization
  • SNMP
  • network monitoring
  • network-administration
  • traffic analysis

Related Articles

Popular Technical Articles & Tutorials

Explore our comprehensive collection of technical articles, programming tutorials, and IT guides written by industry experts:

Browse all 8+ technical articles | Read our IT blog

Bandwidth Monitoring Over Time: Complete Admin Guide