From d30772645d6da3f87b494f386062464ab4ed5d20 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Thu, 22 Oct 2026 15:18:47 -0500 Subject: [PATCH] expose frigate_camera_events as a gauge The metric reports the current count of events in the database, which drops when retention prunes old events. As a counter, each prune read as a counter reset, so increase() and rate() inflated event counts. The series name changes from frigate_camera_events_total to frigate_camera_events. The test's porch/inside assertion was missing its `in event.text` and always passed. --- docs/docs/configuration/metrics.md | 9 ++++----- frigate/stats/prometheus.py | 5 ++--- frigate/test/http_api/test_http_event.py | 21 +++++++++------------ 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/docs/docs/configuration/metrics.md b/docs/docs/configuration/metrics.md index 69db159cc5..480fada5f4 100644 --- a/docs/docs/configuration/metrics.md +++ b/docs/docs/configuration/metrics.md @@ -69,7 +69,7 @@ These gauges report the operating system's figures for the whole filesystem (the ### Event Metrics -- `frigate_camera_events{camera="", label=""}` - Count of camera events since exporter started +- `frigate_camera_events{camera="", label=""}` - Current number of events stored in the database for each camera and label ## Configuring Prometheus @@ -101,8 +101,8 @@ rate(frigate_detection_fps{camera_name="front_door"}[5m]) # Storage usage percentage (frigate_storage_used_bytes / frigate_storage_total_bytes) * 100 -# Event count by camera in last hour -increase(frigate_camera_events[1h]) +# Number of events currently stored in the database by camera +sum by (camera) (frigate_camera_events) ``` ## Grafana Dashboard @@ -121,8 +121,7 @@ A sample Grafana dashboard JSON will be provided in a future update. The metrics exposed by Frigate use the following Prometheus metric types: -- **Counter**: Cumulative values that only increase (e.g., `frigate_camera_events`) -- **Gauge**: Values that can go up and down (e.g., `frigate_cpu_usage_percent`) +- **Gauge**: Values that can go up and down (e.g., `frigate_cpu_usage_percent`, `frigate_camera_events`) - **Info**: Key-value pairs for metadata (e.g., `frigate_storage_mount_type`) For more information about Prometheus metric types, see the [Prometheus documentation](https://prometheus.io/docs/concepts/metric_types/). diff --git a/frigate/stats/prometheus.py b/frigate/stats/prometheus.py index 9797d569e1..db879bd38a 100644 --- a/frigate/stats/prometheus.py +++ b/frigate/stats/prometheus.py @@ -5,7 +5,6 @@ from typing import Any from prometheus_client import CONTENT_TYPE_LATEST, generate_latest from prometheus_client.core import ( REGISTRY, - CounterMetricFamily, GaugeMetricFamily, InfoMetricFamily, ) @@ -472,9 +471,9 @@ class CustomCollector: yield storage_total yield storage_used - camera_events = CounterMetricFamily( + camera_events = GaugeMetricFamily( "frigate_camera_events", - "Count of camera events since exporter started", + "Current number of events stored in the database per camera and label", labels=["camera", "label"], ) diff --git a/frigate/test/http_api/test_http_event.py b/frigate/test/http_api/test_http_event.py index 959fe6dbc2..8de5eb9dbc 100644 --- a/frigate/test/http_api/test_http_event.py +++ b/frigate/test/http_api/test_http_event.py @@ -563,23 +563,20 @@ class TestHttpApp(BaseTestHttp): assert "# TYPE frigate_detection_total_fps gauge" in event.text assert "frigate_detection_total_fps 13.7" in event.text assert ( - "# HELP frigate_camera_events_total Count of camera events since exporter started" + "# HELP frigate_camera_events Current number of events stored in the database per camera and label" in event.text ) - assert "# TYPE frigate_camera_events_total counter" in event.text + assert "# TYPE frigate_camera_events gauge" in event.text assert ( - 'frigate_camera_events_total{camera="front_door",label="Mock"} 3.0' + 'frigate_camera_events{camera="front_door",label="Mock"} 3.0' in event.text + ) + assert ( + 'frigate_camera_events{camera="front_door",label="inside"} 2.0' in event.text ) assert ( - 'frigate_camera_events_total{camera="front_door",label="inside"} 2.0' + 'frigate_camera_events{camera="front_door",label="outside"} 2.0' in event.text ) - assert ( - 'frigate_camera_events_total{camera="front_door",label="outside"} 2.0' - in event.text - ) - assert ( - 'frigate_camera_events_total{camera="porch",label="Mock"} 2.0' in event.text - ) - assert 'frigate_camera_events_total{camera="porch",label="inside"} 2.0' + assert 'frigate_camera_events{camera="porch",label="Mock"} 2.0' in event.text + assert 'frigate_camera_events{camera="porch",label="inside"} 2.0' in event.text