From 32569842d34afd97fe16e9608dd75511c3b3f3f4 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Sun, 11 Jun 2023 07:26:34 -0600 Subject: [PATCH] Option to enable / disable stats that require external processes (#6615) * Add option for network bandwidth and only calculate if enabled * Don't show network bandwidth in system stats page if not enabled * Formatting * Hide other rows as well * Add docs * Add config options for AMD and Intel GPU stats * Fix stats access * Update docs * Use correct bool syntax Co-authored-by: Blake Blackshear --------- Co-authored-by: Blake Blackshear --- docs/docs/configuration/index.md | 8 ++++++++ frigate/config.py | 11 +++++++++++ frigate/stats.py | 25 ++++++++++++++++++------- web/src/routes/System.jsx | 32 +++++++++++++++++++++----------- 4 files changed, 58 insertions(+), 18 deletions(-) diff --git a/docs/docs/configuration/index.md b/docs/docs/configuration/index.md index 1644903a1..980d14465 100644 --- a/docs/docs/configuration/index.md +++ b/docs/docs/configuration/index.md @@ -568,6 +568,14 @@ telemetry: - ens - wl - lo + # Optional: Configure system stats + stats: + # Enable AMD GPU stats (default: shown below) + amd_gpu_stats: True + # Enable Intel GPU stats (default: shown below) + intel_gpu_stats: True + # Enable network bandwidth stats monitoring for camera ffmpeg processes, go2rtc, and object detectors. (default: shown below) + network_bandwidth: False # 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 58545e27c..156a755c5 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -89,11 +89,22 @@ class UIConfig(FrigateBaseModel): ) +class StatsConfig(FrigateBaseModel): + amd_gpu_stats: bool = Field(default=True, title="Enable AMD GPU stats.") + intel_gpu_stats: bool = Field(default=True, title="Enable Intel GPU stats.") + network_bandwidth: bool = Field( + default=False, title="Enable network bandwidth for ffmpeg processes." + ) + + class TelemetryConfig(FrigateBaseModel): network_interfaces: List[str] = Field( default=["eth", "enp", "eno", "ens", "wl", "lo"], title="Enabled network interfaces for bandwidth calculation.", ) + stats: StatsConfig = Field( + default_factory=StatsConfig, title="System Stats Configuration" + ) version_check: bool = Field(default=True, title="Enable latest version check.") diff --git a/frigate/stats.py b/frigate/stats.py index dd8c4b06d..246f74bf1 100644 --- a/frigate/stats.py +++ b/frigate/stats.py @@ -104,13 +104,15 @@ def get_processing_stats( """Get stats for cpu / gpu.""" async def run_tasks() -> None: - await asyncio.wait( - [ - asyncio.create_task(set_gpu_stats(config, stats, hwaccel_errors)), - asyncio.create_task(set_cpu_stats(stats)), - asyncio.create_task(set_bandwidth_stats(config, stats)), - ] - ) + stats_tasks = [ + asyncio.create_task(set_gpu_stats(config, stats, hwaccel_errors)), + asyncio.create_task(set_cpu_stats(stats)), + ] + + if config.telemetry.stats.network_bandwidth: + stats_tasks.append(asyncio.create_task(set_bandwidth_stats(config, stats))) + + await asyncio.wait(stats_tasks) loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) @@ -179,6 +181,9 @@ async def set_gpu_stats( stats["nvidia-gpu"] = {"gpu": -1, "mem": -1} hwaccel_errors.append(args) elif "qsv" in args: + if not config.telemetry.stats.intel_gpu_stats: + continue + # intel QSV GPU intel_usage = get_intel_gpu_stats() @@ -191,6 +196,9 @@ async def set_gpu_stats( driver = os.environ.get(DRIVER_ENV_VAR) if driver == DRIVER_AMD: + if not config.telemetry.stats.amd_gpu_stats: + continue + # AMD VAAPI GPU amd_usage = get_amd_gpu_stats() @@ -200,6 +208,9 @@ async def set_gpu_stats( stats["amd-vaapi"] = {"gpu": -1, "mem": -1} hwaccel_errors.append(args) else: + if not config.telemetry.stats.intel_gpu_stats: + continue + # intel VAAPI GPU intel_usage = get_intel_gpu_stats() diff --git a/web/src/routes/System.jsx b/web/src/routes/System.jsx index bf4c57c45..82c8d619d 100644 --- a/web/src/routes/System.jsx +++ b/web/src/routes/System.jsx @@ -96,7 +96,8 @@ export default function System() { System {service.version} {config && ( - go2rtc {go2rtc && ( `${go2rtc.version} ` ) } + + go2rtc {go2rtc && `${go2rtc.version} `} Inference Speed CPU % Memory % - Network Bandwidth + {config.telemetry.network_bandwidth && Network Bandwidth} @@ -248,7 +249,9 @@ export default function System() { {detectors[detector]['inference_speed']} ms {cpu_usages[detectors[detector]['pid']]?.['cpu'] || '- '}% {cpu_usages[detectors[detector]['pid']]?.['mem'] || '- '}% - {bandwidth_usages[detectors[detector]['pid']]?.['bandwidth'] || '- '}KB/s + {config.telemetry.network_bandwidth && ( + {bandwidth_usages[detectors[detector]['pid']]?.['bandwidth'] || '- '}KB/s + )} @@ -346,25 +349,30 @@ export default function System() { FPS CPU % Memory % - Network Bandwidth + {config.telemetry.network_bandwidth && Network Bandwidth} - ffmpeg + + ffmpeg + > + + {cameras[camera]['ffmpeg_pid'] || '- '} {cameras[camera]['camera_fps'] || '- '} {cpu_usages[cameras[camera]['ffmpeg_pid']]?.['cpu'] || '- '}% {cpu_usages[cameras[camera]['ffmpeg_pid']]?.['mem'] || '- '}% - {bandwidth_usages[cameras[camera]['ffmpeg_pid']]?.['bandwidth'] || '- '}KB/s + {config.telemetry.network_bandwidth && ( + {bandwidth_usages[cameras[camera]['ffmpeg_pid']]?.['bandwidth'] || '- '}KB/s + )} Capture @@ -372,7 +380,7 @@ export default function System() { {cameras[camera]['process_fps'] || '- '} {cpu_usages[cameras[camera]['capture_pid']]?.['cpu'] || '- '}% {cpu_usages[cameras[camera]['capture_pid']]?.['mem'] || '- '}% - - + {config.telemetry.network_bandwidth && -} Detect @@ -393,7 +401,7 @@ export default function System() { {cpu_usages[cameras[camera]['pid']]?.['cpu'] || '- '}% {cpu_usages[cameras[camera]['pid']]?.['mem'] || '- '}% - - + {config.telemetry.network_bandwidth && -} @@ -430,7 +438,7 @@ export default function System() { CPU % Avg CPU % Memory % - Network Bandwidth + {config.telemetry.network_bandwidth && Network Bandwidth} @@ -439,7 +447,9 @@ export default function System() { {cpu_usages[processes[process]['pid']]?.['cpu'] || '- '}% {cpu_usages[processes[process]['pid']]?.['cpu_average'] || '- '}% {cpu_usages[processes[process]['pid']]?.['mem'] || '- '}% - {bandwidth_usages[processes[process]['pid']]?.['bandwidth'] || '- '}KB/s + {config.telemetry.network_bandwidth && ( + {bandwidth_usages[processes[process]['pid']]?.['bandwidth'] || '- '}KB/s + )}