Repository: blakeblackshear/frigate

Issue:
[Support]: nethogs CPU usage
### Describe the problem you are having

I'm seeing nethogs use 20-40% CPU every few seconds (according to htop).

Would be nice to have an option to disable it for people who don't care too much about monitoring bandwidth.

### Version

0.13.0-53d63e0

### Frigate config file

```yaml
n/a
```


### Relevant log output

```shell
n/a
```


### FFprobe output from your camera

```shell
n/a
```


### Frigate stats

_No response_

### Operating system

Debian

### Install method

Docker Compose

### Coral version

USB

### Network connection

Wired

### Camera make and model

n/a

### Any other information that may be helpful

_No response_


Discussion:

Resolving patch:
diff --git a/frigate/config.py b/frigate/config.py
--- 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
--- 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()
 


Test patch: