Add function to get physical interfaces for bandwidth calculation in get_bandwidth_stats() function

This commit is contained in:
Sergey Krashevich 2023-05-26 04:31:06 +03:00
parent 1e17dbaa91
commit e75ef9ad49
No known key found for this signature in database
GPG Key ID: 625171324E7D3856

View File

@ -846,10 +846,24 @@ def get_cpu_stats() -> dict[str, dict]:
return usages
def get_physical_interfaces():
with open("/proc/net/dev", "r") as file:
lines = file.readlines()
physical_interfaces = []
for line in lines:
if ":" in line:
interface = line.split(":")[0].strip()
if interface.startswith(("eth", "enp", "eno", "ens", "wl", "lo")):
physical_interfaces.append(interface)
return physical_interfaces
def get_bandwidth_stats() -> dict[str, dict]:
"""Get bandwidth usages for each ffmpeg process id"""
usages = {}
top_command = ["nethogs", "-t", "-v0", "-c5", "-d1"]
top_command = ["nethogs", "-t", "-v0", "-c5", "-d1"] + get_physical_interfaces()
p = sp.run(
top_command,