Day 4-Monitoring Network Performance at Peak and Non-Peak Hours

Photo by Kevin Ku on Unsplash

Day 4-Monitoring Network Performance at Peak and Non-Peak Hours

In today's interconnected world, a robust and efficient network is the backbone of any successful organization. But how do you ensure consistent performance, especially during peak hours? In this blog, we'll explore a real-world use case from TechFusion Corp., detailing how they proactively monitored and analyzed their network's performance using Python.

The Challenge:

TechFusion Corp., amidst rapid expansion, faced the challenge of ensuring optimal network performance across an increasing number of devices and users. Jane, their astute network administrator, recognized the need to gauge the network's health during different times of the day, especially during peak business hours.

The Strategy:

To get a snapshot of the network's health, Jane decided on a straightforward metric: the ping response time to By pinging this external site from all devices at specific intervals, she aimed to understand the network's behavior.

Monitoring Intervals:

  • Peak Hours: 9 am, 1:30 pm, and 4 pm.

  • Non-Peak Hours: 6 am and 10 pm.

The Implementation:

1. Organizing Device Details:

Jane maintained a CSV file, devices.csv, to store essential details for each device:

# device_type,ip,username,password,secret

2. Crafting the Python Script:

Jane's Python script performed the following tasks:

import csv
import subprocess
import datetime

def ping_google_from_device(device):
    # Construct the command to SSH into the device and ping
    cmd = f"ssh {device['username']}@{device['ip']} 'ping -c 4'"
    response =, capture_output=True, text=True, shell=True)

    timestamp ='%Y-%m-%d %H:%M:%S')
    with open('network_performance.txt', 'a') as file:
        file.write(f"Timestamp: {timestamp}, Device: {device['ip']}\n")
        file.write("\n" + "-"*50 + "\n")

if __name__ == "__main__":
    devices = []

    with open('devices.csv', 'r') as file:
        reader = csv.DictReader(file)
        for row in reader:

    for device in devices:

This script reads the device details, logs into each device, pings, and logs the results with timestamps.

3. Automating the Process:

To ensure the script ran at the desired times:

  • Linux: Jane used the cron job scheduler.

  • Windows: Jane could employ the built-in Task Scheduler.

Scheduling the Script:

For Linux:

Use cron to schedule the script. Open the crontab editor:

crontab -e

Add the following lines to run the script at 9 am, 1:30 pm, and 10 pm:

0 9 * * * /usr/bin/python3 /path/to/
30 13 * * * /usr/bin/python3 /path/to/
0 22 * * * /usr/bin/python3 /path/to/

The Insights:

After several weeks, the network_performance.txt log provided invaluable data. Jane observed slightly higher ping response times during peak hours, hinting at potential network congestion. This data empowered her to consider network optimizations or upgrades to enhance performance during high-traffic periods.