abdulsamad786 / TCP-Network-Connection-Monitoring-with-Python

The project deals with advanced data structures and concepts used by Python such as: Queues and Threads to understand this project. This Python script or agent is used to read tcp connection statistics from kernel via /proc file. Majority of Linux stats tool read performance statistics using /proc file. /proc is a pseudo filesystem in Linux that allows user applications or stats tool to read kernel statistics by simply reading a /proc file (# cat /proc/stats). For example: vmstat tool that reads memory statistics from kernel uses /proc/meminfo and /proc/vmstat files iostat tool that reads disk statistics from kernel uses /proc/diskstats file mpstat tool that reads cpu statistics from kernel uses /proc/stat file pidstat that read per process memory and cpu statistics from kernel uses /proc/pid/stat file netstat that reads network statistics from kernel uses /proc/net/netstat or /proc/net/dev files TCP per connection statistics is generated by open source kernel module tcp_probe . Kernel driver makes TCP statistics available via /proc file. TCP statistics include: connection latency, throughput and other stats such as: packet Round Trip Time (RTT), Commulative Bytes transferred, packet retransmission and additional stats. Each line read via /proc file has a unique quadruplet: Source IP address, Source Port, Destination IP address and Destination Port and relevant tcp statistics. After the tcpprobe kernel module is loaded, one can read statistics by simply doing: # cat /proc/net/tcpprobe Python agent reads these tcp connection statistics via /proc/net/tcpprobe and appends it into Queue data structure with a timestamp. Another thread that blocks on HTTP request reads these connection stats from the Queue and delivers it as a JSON object. Web clients (Java scripts) has libraries to interpret JSON objects and can use it to build performance dashboard
5 stars 4 forks source link