Add a notice registry and System Health tab (#24178)

* add a notice registry and System Health tab

Problems Frigate detects on its own (ffmpeg crash loops, stuck detectors, failed model downloads, recordings deleted before their retention period) only ever existed as log lines. This adds a `NoticeRegistry` in the main process backed by two tables, an `update_notice` IPC topic so producers in other processes can reach it through the dispatcher, an admin-only API and websocket topic, and a Health tab that lists them. Kinds declare their own mode, severity, and category in one place: state notices are resolved by their producer, event notices are dismissed by the user.

* treat a prerelease as behind its final release

* fix notices clearing early

* rename menu items and update docs

* don't resolve the update notice on a failed version lookup
This commit is contained in:
Josh Hawkins
2026-09-12 07:30:04 -06:00
committed by Nicolas Mowen
parent af60d2db48
commit f3a31e2fb4
55 changed files with 2346 additions and 117 deletions
+48 -1
View File
@@ -11,16 +11,21 @@ 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.notices.registry import NoticeRegistry
from frigate.stats.hardware import HardwareStats
from frigate.stats.prometheus import update_metrics
from frigate.stats.util import stats_snapshot
from frigate.stats.util import get_latest_version, is_newer_version, stats_snapshot
from frigate.types import StatsTrackingTypes
from frigate.version import VERSION
logger = logging.getLogger(__name__)
MAX_STATS_POINTS = 80
# how often to ask GitHub for the latest release
VERSION_REFRESH_S = 24 * 60 * 60
class StatsEmitter(threading.Thread):
def __init__(
@@ -28,11 +33,13 @@ class StatsEmitter(threading.Thread):
config: FrigateConfig,
stats_tracking: StatsTrackingTypes,
stop_event: MpEvent,
notice_registry: NoticeRegistry | None = None,
):
super().__init__(name="frigate_stats_emitter")
self.config = config
self.stats_tracking = stats_tracking
self.stop_event = stop_event
self.notice_registry = notice_registry
self.hardware_stats = HardwareStats(config)
self.stats_history: list[dict[str, Any]] = []
@@ -125,14 +132,54 @@ class StatsEmitter(threading.Thread):
update_metrics(stats)
return stats
def _check_update_notice(self) -> None:
"""Raise or resolve the update notice from the tracked latest version."""
if self.notice_registry is None:
return
latest = self.stats_tracking["latest_frigate_version"]
# a failed lookup says nothing about whether an update exists
if latest == "unknown":
return
if is_newer_version(VERSION, latest):
self.notice_registry.raise_notice(
"update_available", params={"version": latest}
)
else:
self.notice_registry.resolve("update_available")
def _refresh_latest_version(self) -> None:
"""Refresh the latest release on a daemon thread so the request never stalls stats."""
def refresh() -> None:
latest = get_latest_version(self.config)
# keep the last good value; stats surface it as service.latest_version
if latest != "unknown":
self.stats_tracking["latest_frigate_version"] = latest
self._check_update_notice()
threading.Thread(
target=refresh, name="frigate_version_check", daemon=True
).start()
def run(self) -> None:
time.sleep(10)
self._check_update_notice()
last_version_check = time.time()
for counter in itertools.cycle(
range(int(self.config.mqtt.stats_interval / FREQUENCY_STATS_POINTS))
):
if self.stop_event.wait(FREQUENCY_STATS_POINTS):
break
if time.time() - last_version_check >= VERSION_REFRESH_S:
self._refresh_latest_version()
last_version_check = time.time()
logger.debug("Starting stats collection")
stats = stats_snapshot(
self.config, self.stats_tracking, self.hardware_stats
+37
View File
@@ -1,6 +1,7 @@
"""Utilities for stats."""
import logging
import re
import shutil
import time
from json import JSONDecodeError
@@ -45,6 +46,42 @@ def get_latest_version(config: FrigateConfig) -> str:
return "unknown"
def _version_tuple(value: str) -> tuple[int, int, int] | None:
match = re.match(r"^(\d+)\.(\d+)\.(\d+)", value or "")
if match is None:
return None
return int(match.group(1)), int(match.group(2)), int(match.group(3))
# a build's git hash suffix is not a prerelease marker
PRERELEASE_PATTERN = re.compile(r"^\d+\.\d+\.\d+-(?:beta|rc)", re.IGNORECASE)
def _is_prerelease(value: str) -> bool:
return PRERELEASE_PATTERN.match(value or "") is not None
def is_newer_version(current: str, latest: str) -> bool:
"""Whether latest is a release newer than the running version.
Build suffixes after the third number are ignored, and a value that does
not parse (disabled, unknown) is never newer. A prerelease is behind the
final release of the same number, so 0.19.0-beta2 is behind 0.19.0.
"""
current_tuple = _version_tuple(current)
latest_tuple = _version_tuple(latest)
if current_tuple is None or latest_tuple is None:
return False
if current_tuple == latest_tuple:
return _is_prerelease(current) and not _is_prerelease(latest)
return latest_tuple > current_tuple
def stats_init(
config: FrigateConfig,
camera_metrics: DictProxy,