mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-07-14 16:01:13 +03:00
add shortcut for admins in /stats
This commit is contained in:
parent
b2e16ee5de
commit
b0caf5253d
@ -101,6 +101,11 @@ def stats(
|
|||||||
allowed_cameras: List[str] = Depends(get_allowed_cameras_for_filter),
|
allowed_cameras: List[str] = Depends(get_allowed_cameras_for_filter),
|
||||||
):
|
):
|
||||||
stats_data = request.app.stats_emitter.get_latest_stats()
|
stats_data = request.app.stats_emitter.get_latest_stats()
|
||||||
|
|
||||||
|
# Admins see the full snapshot
|
||||||
|
if request.headers.get("remote-role") == "admin":
|
||||||
|
return JSONResponse(content=stats_data)
|
||||||
|
|
||||||
allowed_set = set(allowed_cameras)
|
allowed_set = set(allowed_cameras)
|
||||||
|
|
||||||
# Shallow-copy so we don't mutate the cached stats history entry.
|
# Shallow-copy so we don't mutate the cached stats history entry.
|
||||||
@ -118,15 +123,14 @@ def stats(
|
|||||||
name: data for name, data in bandwidth.items() if name in allowed_set
|
name: data for name, data in bandwidth.items() if name in allowed_set
|
||||||
}
|
}
|
||||||
|
|
||||||
# cmdline can leak camera URLs/paths; strip for non-admin but keep
|
# cmdline can leak camera URLs/paths; strip but keep cpu/mem so
|
||||||
# cpu/mem so client-side problem heuristics still work.
|
# client-side problem heuristics still work.
|
||||||
if request.headers.get("remote-role") != "admin":
|
cpu_usages = stats_data.get("cpu_usages")
|
||||||
cpu_usages = stats_data.get("cpu_usages")
|
if cpu_usages is not None:
|
||||||
if cpu_usages is not None:
|
filtered["cpu_usages"] = {
|
||||||
filtered["cpu_usages"] = {
|
pid: {k: v for k, v in usage.items() if k != "cmdline"}
|
||||||
pid: {k: v for k, v in usage.items() if k != "cmdline"}
|
for pid, usage in cpu_usages.items()
|
||||||
for pid, usage in cpu_usages.items()
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return JSONResponse(content=filtered)
|
return JSONResponse(content=filtered)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user