diff --git a/docs/docs/configuration/index.md b/docs/docs/configuration/index.md index 0a1b230aa..d40d235b9 100644 --- a/docs/docs/configuration/index.md +++ b/docs/docs/configuration/index.md @@ -558,6 +558,14 @@ ui: # Optional: Telemetry configuration telemetry: + # Optional: Enabled network interfaces for bandwidth stats monitoring (default: shown below) + network_interfaces: + - eth + - enp + - eno + - ens + - wl + - lo # Optional: Enable the latest version outbound check (default: shown below) # NOTE: If you use the HomeAssistant integration, disabling this will prevent it from reporting new versions version_check: True diff --git a/frigate/config.py b/frigate/config.py index 56e4dc496..ce059b56a 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -102,6 +102,10 @@ class UIConfig(FrigateBaseModel): class TelemetryConfig(FrigateBaseModel): + network_interfaces: List[str] = Field( + default=["eth", "enp", "eno", "ens", "wl", "lo"], + title="Enabled network interfaces for bandwidth calculation.", + ) version_check: bool = Field(default=True, title="Enable latest version check.") diff --git a/frigate/stats.py b/frigate/stats.py index 55db809d3..f6a407736 100644 --- a/frigate/stats.py +++ b/frigate/stats.py @@ -101,7 +101,7 @@ def get_processing_stats( [ asyncio.create_task(set_gpu_stats(config, stats, hwaccel_errors)), asyncio.create_task(set_cpu_stats(stats)), - asyncio.create_task(set_bandwidth_stats(stats)), + asyncio.create_task(set_bandwidth_stats(config, stats)), ] ) @@ -119,9 +119,9 @@ async def set_cpu_stats(all_stats: dict[str, Any]) -> None: all_stats["cpu_usages"] = cpu_stats -async def set_bandwidth_stats(all_stats: dict[str, Any]) -> None: +async def set_bandwidth_stats(config: FrigateConfig, all_stats: dict[str, Any]) -> None: """Set bandwidth from nethogs.""" - bandwidth_stats = get_bandwidth_stats() + bandwidth_stats = get_bandwidth_stats(config) if bandwidth_stats: all_stats["bandwidth_usages"] = bandwidth_stats diff --git a/frigate/util.py b/frigate/util.py index 92ad12b44..770ea103c 100755 --- a/frigate/util.py +++ b/frigate/util.py @@ -846,7 +846,7 @@ def get_cpu_stats() -> dict[str, dict]: return usages -def get_physical_interfaces(): +def get_physical_interfaces(interfaces) -> list: with open("/proc/net/dev", "r") as file: lines = file.readlines() @@ -854,16 +854,19 @@ def get_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) + for int in interfaces: + if interface.startswith(int): + physical_interfaces.append(interface) return physical_interfaces -def get_bandwidth_stats() -> dict[str, dict]: +def get_bandwidth_stats(config) -> dict[str, dict]: """Get bandwidth usages for each ffmpeg process id""" usages = {} - top_command = ["nethogs", "-t", "-v0", "-c5", "-d1"] + get_physical_interfaces() + top_command = ["nethogs", "-t", "-v0", "-c5", "-d1"] + get_physical_interfaces( + config.telemetry.network_interfaces + ) p = sp.run( top_command,