Implement general page of system graphs (#10815)

* Reorganize stats and show graphs in system metrics

* Break apart all cpu / mem graphs

* Auto update stats

* Show camera graphs

* Get system graphs working for inference time

* Update stats every 10 seconds, keeping the last 10 minutes

* Use types for thresholds

* Use keys api

* Break system metrics into different pages

* Add dialog for viewing and copying vainfo

* remove unused for now

* Formatting

* Make tooltip match theme

* Make betters color in light mode

* Include gpu

* Make scaling consistent

* Fix name

* address feedback
This commit is contained in:
Nicolas Mowen
2024-04-03 21:22:11 -06:00
committed by GitHub
parent 427c6a6afb
commit 0096a6d778
11 changed files with 884 additions and 22 deletions

View File

@@ -127,7 +127,12 @@ def stats():
@bp.route("/stats/history")
def stats_history():
return jsonify(current_app.stats_emitter.get_stats_history())
keys = request.args.get("keys", default=None)
if keys:
keys = keys.split(",")
return jsonify(current_app.stats_emitter.get_stats_history(keys))
@bp.route("/config")

View File

@@ -1,10 +1,12 @@
"""Emit stats to listeners."""
import itertools
import json
import logging
import threading
import time
from multiprocessing.synchronize import Event as MpEvent
from typing import Optional
from frigate.comms.inter_process import InterProcessRequestor
from frigate.config import FrigateConfig
@@ -14,6 +16,9 @@ from frigate.types import StatsTrackingTypes
logger = logging.getLogger(__name__)
MAX_STATS_POINTS = 120
class StatsEmitter(threading.Thread):
def __init__(
self,
@@ -43,19 +48,43 @@ class StatsEmitter(threading.Thread):
self.stats_history.append(stats)
return stats
def get_stats_history(self) -> list[dict[str, any]]:
def get_stats_history(
self, keys: Optional[list[str]] = None
) -> list[dict[str, any]]:
"""Get stats history."""
return self.stats_history
if not keys:
return self.stats_history
selected_stats: list[dict[str, any]] = []
for s in self.stats_history:
selected = {}
for k in keys:
selected[k] = s.get(k)
selected_stats.append(selected)
return selected_stats
def run(self) -> None:
time.sleep(10)
while not self.stop_event.wait(self.config.mqtt.stats_interval):
for counter in itertools.cycle(
range(int(self.config.mqtt.stats_interval / 10))
):
if self.stop_event.wait(10):
break
logger.debug("Starting stats collection")
stats = stats_snapshot(
self.config, self.stats_tracking, self.hwaccel_errors
)
self.stats_history.append(stats)
self.stats_history = self.stats_history[-10:]
self.requestor.send_data("stats", json.dumps(stats))
self.stats_history = self.stats_history[-MAX_STATS_POINTS:]
if counter == 0:
self.requestor.send_data("stats", json.dumps(stats))
logger.debug("Finished stats collection")
logger.info("Exiting stats emitter...")