mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-05 02:35:22 +03:00
test refactor process stats
This commit is contained in:
parent
b38c9e82e2
commit
135344ec46
@ -8,6 +8,7 @@ import signal
|
||||
import sys
|
||||
from typing import Optional
|
||||
from types import FrameType
|
||||
import psutil
|
||||
|
||||
import traceback
|
||||
from peewee_migrate import Router
|
||||
@ -58,6 +59,7 @@ class FrigateApp:
|
||||
self.plus_api = PlusApi()
|
||||
self.camera_metrics: dict[str, CameraMetricsTypes] = {}
|
||||
self.record_metrics: dict[str, RecordMetricsTypes] = {}
|
||||
self.processes: dict[str, int]
|
||||
|
||||
def set_environment_vars(self) -> None:
|
||||
for key, value in self.config.environment_vars.items():
|
||||
@ -171,6 +173,12 @@ class FrigateApp:
|
||||
|
||||
migrate_db.close()
|
||||
|
||||
def init_go2rtc(self) -> None:
|
||||
for proc in psutil.process_iter(['pid', 'name']):
|
||||
if proc.info['name'] == 'go2rtc':
|
||||
self.processes["go2rtc"] = proc.info['pid']
|
||||
|
||||
|
||||
def init_recording_manager(self) -> None:
|
||||
recording_process = mp.Process(
|
||||
target=manage_recordings,
|
||||
@ -179,6 +187,7 @@ class FrigateApp:
|
||||
)
|
||||
recording_process.daemon = True
|
||||
self.recording_process = recording_process
|
||||
self.processes["recording"] = recording_process.pid
|
||||
recording_process.start()
|
||||
logger.info(f"Recording process started: {recording_process.pid}")
|
||||
|
||||
@ -191,7 +200,7 @@ class FrigateApp:
|
||||
|
||||
def init_stats(self) -> None:
|
||||
self.stats_tracking = stats_init(
|
||||
self.config, self.camera_metrics, self.detectors
|
||||
self.config, self.camera_metrics, self.detectors, self.processes
|
||||
)
|
||||
|
||||
def init_web_server(self) -> None:
|
||||
@ -412,6 +421,7 @@ class FrigateApp:
|
||||
self.init_database()
|
||||
self.init_onvif()
|
||||
self.init_recording_manager()
|
||||
self.init_go2rtc()
|
||||
self.bind_database()
|
||||
self.init_dispatcher()
|
||||
except Exception as e:
|
||||
|
||||
@ -46,6 +46,7 @@ def stats_init(
|
||||
config: FrigateConfig,
|
||||
camera_metrics: dict[str, CameraMetricsTypes],
|
||||
detectors: dict[str, ObjectDetectProcess],
|
||||
processes: dict[str, int],
|
||||
) -> StatsTrackingTypes:
|
||||
stats_tracking: StatsTrackingTypes = {
|
||||
"camera_metrics": camera_metrics,
|
||||
@ -53,6 +54,7 @@ def stats_init(
|
||||
"started": int(time.time()),
|
||||
"latest_frigate_version": get_latest_version(config),
|
||||
"last_updated": int(time.time()),
|
||||
"processes": processes,
|
||||
}
|
||||
return stats_tracking
|
||||
|
||||
@ -260,6 +262,12 @@ def stats_snapshot(
|
||||
"mount_type": get_fs_type(path),
|
||||
}
|
||||
|
||||
stats["processes"] = {}
|
||||
for name, pid in stats_tracking["processes"].items():
|
||||
stats["processes"][name] = {
|
||||
"pid": pid,
|
||||
}
|
||||
|
||||
return stats
|
||||
|
||||
|
||||
|
||||
@ -817,13 +817,7 @@ def get_cpu_stats() -> dict[str, dict]:
|
||||
else:
|
||||
mem_pct = round((mem_res / total_mem) * 100, 1)
|
||||
|
||||
idx = pid
|
||||
if stats[1] == "(go2rtc)":
|
||||
idx = "go2rtc"
|
||||
if stats[1].startswith("(frigate.r"):
|
||||
idx = "recording"
|
||||
|
||||
usages[idx] = {
|
||||
usages[pid] = {
|
||||
"cpu": str(round(cpu_usage, 2)),
|
||||
"mem": f"{mem_pct}",
|
||||
}
|
||||
|
||||
@ -29,12 +29,14 @@ export default function System() {
|
||||
detectors,
|
||||
service = {},
|
||||
detection_fps: _,
|
||||
processes,
|
||||
...cameras
|
||||
} = stats || initialStats || emptyObject;
|
||||
|
||||
const detectorNames = Object.keys(detectors || emptyObject);
|
||||
const gpuNames = Object.keys(gpu_usages || emptyObject);
|
||||
const cameraNames = Object.keys(cameras || emptyObject);
|
||||
const processesNames = Object.keys(processes || emptyObject);
|
||||
|
||||
const onHandleFfprobe = async (camera, e) => {
|
||||
if (e) {
|
||||
@ -347,7 +349,7 @@ export default function System() {
|
||||
|
||||
<Heading size="lg">Other Processes</Heading>
|
||||
<div data-testid="cameras" className="grid grid-cols-1 3xl:grid-cols-3 md:grid-cols-2 gap-4">
|
||||
{['go2rtc', 'recording'].map((process) => (
|
||||
{processesNames.map((process) => (
|
||||
<div key={process} className="dark:bg-gray-800 shadow-md hover:shadow-lg rounded-lg transition-shadow">
|
||||
<div className="capitalize text-lg flex justify-between p-4">
|
||||
<div className="text-lg flex justify-between">{process}</div>
|
||||
@ -362,8 +364,8 @@ export default function System() {
|
||||
</Thead>
|
||||
<Tbody>
|
||||
<Tr key="ffmpeg" index="0">
|
||||
<Td>{cpu_usages[process]?.['cpu'] || '- '}%</Td>
|
||||
<Td>{cpu_usages[process]?.['mem'] || '- '}%</Td>
|
||||
<Td>{cpu_usages[processes[process]['pid']]?.['cpu'] || '- '}%</Td>
|
||||
<Td>{cpu_usages[processes[process]['pid']]?.['mem'] || '- '}%</Td>
|
||||
</Tr>
|
||||
</Tbody>
|
||||
</Table>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user