mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-12-03 02:37:06 +03:00
calculate dropped frames notice like skipped detections (#25093)
CI / ARM Build (push) Canceled after 0s
CI / AMD64 Build (push) Canceled after 0s
CI / Jetson Jetpack 6 (push) Canceled after 0s
CI / AMD64 Smoke Test (push) Canceled after 0s
CI / AMD64 Extra Build (push) Canceled after 0s
CI / ARM Extra Build (push) Canceled after 0s
CI / Synaptics Build (push) Canceled after 0s
CI / Assemble and push default build (push) Canceled after 0s
CI / ARM Build (push) Canceled after 0s
CI / AMD64 Build (push) Canceled after 0s
CI / Jetson Jetpack 6 (push) Canceled after 0s
CI / AMD64 Smoke Test (push) Canceled after 0s
CI / AMD64 Extra Build (push) Canceled after 0s
CI / ARM Extra Build (push) Canceled after 0s
CI / Synaptics Build (push) Canceled after 0s
CI / Assemble and push default build (push) Canceled after 0s
The object_processing_behind notice fired after 5 dropped frames in 30 seconds per camera, which doesn't scale with detect fps, tripped on a single short stall, and never resolved. Camera processes now track a dropped frame rate, exposed as dropped_fps and dropped_pct in /api/stats, and the stats emitter raises one system notice when drops stay at or above 5% for over a minute, the same rule as skipped detections. The queue hand-off uses put_nowait so a camera that loses the race for the last slot counts a drop instead of blocking and showing up as skipped frames. Also adds a troubleshooting section to the cpu docs explaining the notice.
This commit is contained in:
@@ -10,7 +10,7 @@ from typing import Any
|
||||
|
||||
from frigate.comms.inter_process import InterProcessRequestor
|
||||
from frigate.config import FrigateConfig
|
||||
from frigate.const import FREQUENCY_STATS_POINTS
|
||||
from frigate.const import FREQUENCY_STATS_POINTS, REPLAY_CAMERA_PREFIX
|
||||
from frigate.notices import flush_notices, raise_notice, resolve_kind, resolve_notice
|
||||
from frigate.stats.hardware import HardwareStats
|
||||
from frigate.stats.prometheus import update_metrics
|
||||
@@ -29,6 +29,10 @@ VERSION_REFRESH_S = 24 * 60 * 60
|
||||
# a camera skipping at least this percent of its frames is falling behind
|
||||
SKIPPED_DETECTIONS_PCT = 5
|
||||
|
||||
# a camera dropping at least this percent of its frames because the tracked
|
||||
# object processor is behind
|
||||
DROPPED_FRAMES_PCT = 5
|
||||
|
||||
# lifetime CPU averages at or above these are high; they match
|
||||
# CameraFfmpegThreshold.error and CameraDetectThreshold.error in the UI
|
||||
FFMPEG_HIGH_CPU_PCT = 20
|
||||
@@ -102,6 +106,7 @@ class StatsEmitter(threading.Thread):
|
||||
self.hardware_stats = HardwareStats(config)
|
||||
self.stats_history: list[dict[str, Any]] = []
|
||||
self.skipped_detections = EpisodeTracker(SKIPPED_DETECTIONS_PCT)
|
||||
self.dropped_frames = EpisodeTracker(DROPPED_FRAMES_PCT)
|
||||
self.ffmpeg_cpu = EpisodeTracker(FFMPEG_HIGH_CPU_PCT)
|
||||
self.detect_cpu = EpisodeTracker(DETECT_HIGH_CPU_PCT)
|
||||
|
||||
@@ -269,6 +274,17 @@ class StatsEmitter(threading.Thread):
|
||||
params={"pct": skipped[camera]},
|
||||
)
|
||||
|
||||
# all cameras share one processor, so the episode spans every camera.
|
||||
# a replay camera's own drops are ignored since it can outpace real time
|
||||
dropped = [
|
||||
camera_stats["dropped_pct"]
|
||||
for camera, camera_stats in cameras.items()
|
||||
if not camera.startswith(REPLAY_CAMERA_PREFIX)
|
||||
]
|
||||
|
||||
if self.dropped_frames.update({"all": max(dropped, default=0.0)}, now):
|
||||
raise_notice("object_processing_behind")
|
||||
|
||||
# high ffmpeg and detect CPU
|
||||
for tracker, kind, pid_key in (
|
||||
(self.ffmpeg_cpu, "ffmpeg_high_cpu", "ffmpeg_pid"),
|
||||
|
||||
+16
-7
@@ -232,16 +232,16 @@ def embeddings_stats(
|
||||
return stats
|
||||
|
||||
|
||||
def skipped_percent(skipped_fps: float, camera_fps: float, enabled: bool) -> float:
|
||||
"""Percent of a camera's frames dropped before detection.
|
||||
def frame_percent(fps: float, camera_fps: float, enabled: bool) -> float:
|
||||
"""Share of a camera's frames, in percent, that a rate such as skipped_fps represents.
|
||||
|
||||
camera_fps counts the dropped frames too. A disabled camera keeps its last
|
||||
readings, so it reports zero.
|
||||
camera_fps counts every frame read from the camera. A disabled camera keeps
|
||||
its last readings, so it reports zero.
|
||||
"""
|
||||
if not enabled or camera_fps <= 0:
|
||||
return 0.0
|
||||
|
||||
return round(skipped_fps / camera_fps * 100, 1)
|
||||
return round(fps / camera_fps * 100, 1)
|
||||
|
||||
|
||||
def get_go2rtc_pid(cpu_usages: dict[str, dict[str, Any]]) -> int | None:
|
||||
@@ -262,7 +262,8 @@ def stats_snapshot(
|
||||
camera_metrics = stats_tracking["camera_metrics"]
|
||||
stats: dict[str, Any] = {}
|
||||
|
||||
total_camera_fps = total_process_fps = total_skipped_fps = total_detection_fps = 0
|
||||
total_camera_fps = total_process_fps = total_skipped_fps = total_dropped_fps = 0
|
||||
total_detection_fps = 0
|
||||
|
||||
stats["cameras"] = {}
|
||||
for name, camera_stats in list(camera_metrics.items()):
|
||||
@@ -273,6 +274,7 @@ def stats_snapshot(
|
||||
total_camera_fps += camera_stats.camera_fps.value
|
||||
total_process_fps += camera_stats.process_fps.value
|
||||
total_skipped_fps += camera_stats.skipped_fps.value
|
||||
total_dropped_fps += camera_stats.dropped_fps.value
|
||||
total_detection_fps += camera_stats.detection_fps.value
|
||||
pid = camera_stats.process_pid.value if camera_stats.process_pid.value else None
|
||||
ffmpeg_pid = camera_stats.ffmpeg_pid.value if camera_stats.ffmpeg_pid else None
|
||||
@@ -311,11 +313,17 @@ def stats_snapshot(
|
||||
"camera_fps": round(camera_stats.camera_fps.value, 2),
|
||||
"process_fps": round(camera_stats.process_fps.value, 2),
|
||||
"skipped_fps": round(camera_stats.skipped_fps.value, 2),
|
||||
"skipped_pct": skipped_percent(
|
||||
"skipped_pct": frame_percent(
|
||||
camera_stats.skipped_fps.value,
|
||||
current_fps,
|
||||
config.cameras[name].enabled,
|
||||
),
|
||||
"dropped_fps": round(camera_stats.dropped_fps.value, 2),
|
||||
"dropped_pct": frame_percent(
|
||||
camera_stats.dropped_fps.value,
|
||||
current_fps,
|
||||
config.cameras[name].enabled,
|
||||
),
|
||||
"detection_fps": round(camera_stats.detection_fps.value, 2),
|
||||
"detection_enabled": camera_config.detect.enabled,
|
||||
"pid": pid,
|
||||
@@ -330,6 +338,7 @@ def stats_snapshot(
|
||||
stats["camera_fps"] = round(total_camera_fps, 2)
|
||||
stats["process_fps"] = round(total_process_fps, 2)
|
||||
stats["skipped_fps"] = round(total_skipped_fps, 2)
|
||||
stats["dropped_fps"] = round(total_dropped_fps, 2)
|
||||
stats["detection_fps"] = round(total_detection_fps, 2)
|
||||
|
||||
stats["embeddings"] = embeddings_stats(
|
||||
|
||||
Reference in New Issue
Block a user