Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to get physical interfaces for bandwidth calculation #6618

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/docs/configuration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions frigate/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")


Expand Down
6 changes: 3 additions & 3 deletions frigate/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ async def run_tasks() -> None:
[
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)),
]
)

Expand All @@ -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
Expand Down
21 changes: 19 additions & 2 deletions frigate/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,10 +846,27 @@ def get_cpu_stats() -> dict[str, dict]:
return usages


def get_bandwidth_stats() -> dict[str, dict]:
def get_physical_interfaces(interfaces) -> list:
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()
for int in interfaces:
if interface.startswith(int):
physical_interfaces.append(interface)

return physical_interfaces


def get_bandwidth_stats(config) -> 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(
config.telemetry.network_interfaces
)

p = sp.run(
top_command,
Expand Down