r/learnpython • • 2d ago

need to build a network performance monitoring tool

I hope this is perfect sub to post.
I need to build network performance monitoring and anomaly detection tool. I need to make something built with an admin dashboard and easy to set up , register a device and monitor easy to run on low resources.

the biggest challange is how to monitor and detect a registred device by an IP address(my be dynamic) is there any way?
which protocols i have to explore for detection and reporting ?
I'm a little bit familiar with python programming .

any advise or suggestion regarding workflow or implementation will be appreciated?

1 Upvotes

10 comments sorted by

1

u/white-9igga 2d ago

for the dynamic ip thing, the usual trick is to flip it around, dont make your server go find the devices, make each device phone home. you put a small python script (or an agent like telegraf or node exporter) on each device that sends its stats to your server every 10-30 seconds with a device id or name that you register once, so the ip can change as much as it wants and you still know who is who. if a device stops reporting for a few minutes, thats your "down" alert.

for what to measure, ping (latency and packet loss), simple tcp connect checks on the ports that matter, and snmp if you are watching routers or switches (pysnmp is the python lib for that). for the dashboard on low resources, sqlite or a small timeseries db plus flask or fastapi is plenty to start with.

anomaly detection can start dumb, like compare the latest value to the average and standard deviation of the last hour, flag it if its way off. you can get fancy later once the data is flowing :)

2

u/Terrible-Disaster774 1d ago

Thanks for a lots of idea your idea

1

u/Massive_Distance_616 2d ago

Building on the phone-home approach that's the right call for the dynamic IP problem. One thing worth adding: issue each device an actual registration token/API key when it phones home for the first time, not just a device name/ID, so a rogue device on the network can't spoof another device's identity by reporting under its name.

For anything that can't run your Python agent (routers, switches, printers, other LAN gear), you can still avoid depending on IP by tracking the device's MAC address via the ARP table or DHCP lease list instead the IP can change on a lease renewal, but the MAC stays constant.

On the anomaly detection side, be careful with a straightforward mean/stddev of the last hour two problems there. First, network metrics like latency and traffic volume usually follow a daily pattern (busier in daytime, quieter overnight), so a flat "last hour average" will flag normal daytime traffic as anomalous compared to a quiet 3am baseline.

Second, mean and standard deviation are themselves distorted by the spikes you're trying to catch one bad outlier inflates the stddev enough that the next real anomaly can slip under the threshold. A fix that's still simple to implement: compare the current reading against the median and MAD (median absolute deviation) for that same hour-of-day window across the trailing couple of weeks, rather than a rolling mean/stddev of the last hour. That handles the daily cycle and isn't thrown off by past spikes, with no extra libraries needed.

For storage on low-resource hardware, SQLite will handle this fine at a small scale, but if you're logging every device every 10-30 seconds indefinitely the table will grow quickly turning on WAL mode (PRAGMA journal_mode=WAL) will stop frequent writes from blocking your dashboard's reads. Worth deciding early on a retention/downsampling policy too: keep raw readings at full resolution for a day or two, then roll older data up into 5 or 15-minute averages, so storage stays roughly flat over time instead of growing forever.

1

u/Terrible-Disaster774 1d ago

Really liked they way you came up with Thank you

1

u/Lumethys 2d ago

OpenTelemetry and whatever O11Y backend of your choice. I prefer VictoriaStack

1

u/avalexva 1d ago

one more trick for the dynamic ip problem that nobody mentioned: put the devices on tailscale. each device gets a stable 100.x address that stays the same no matter what network or ip it sits on, so the whole discovery headache just goes away. free tier covers plenty of devices and the agent is tiny, which fits your low-resource requirement.

you'd still do the phone-home thing for the actual metrics, tailscale just guarantees you can always reach the box itself when you need to poke it manually. saved me a lot of pain on a similar setup :)

1

u/beevek 15h ago

why do you need to build vs leveraging off the shelf tech? grafana cloud at free tier with orb/pktvisor gets you a long way.