mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-03 01:35:22 +03:00
Add support for cpu usage stats
This commit is contained in:
parent
77d86de177
commit
da5e800e6c
@ -14,6 +14,7 @@ from frigate.config import FrigateConfig
|
|||||||
from frigate.const import RECORD_DIR, CLIPS_DIR, CACHE_DIR
|
from frigate.const import RECORD_DIR, CLIPS_DIR, CACHE_DIR
|
||||||
from frigate.types import StatsTrackingTypes, CameraMetricsTypes
|
from frigate.types import StatsTrackingTypes, CameraMetricsTypes
|
||||||
from frigate.version import VERSION
|
from frigate.version import VERSION
|
||||||
|
from frigate.util import get_cpu_stats
|
||||||
from frigate.object_detection import ObjectDetectProcess
|
from frigate.object_detection import ObjectDetectProcess
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -116,6 +117,8 @@ def stats_snapshot(stats_tracking: StatsTrackingTypes) -> dict[str, Any]:
|
|||||||
}
|
}
|
||||||
stats["detection_fps"] = round(total_detection_fps, 2)
|
stats["detection_fps"] = round(total_detection_fps, 2)
|
||||||
|
|
||||||
|
stats["cpu_usages"] = get_cpu_stats()
|
||||||
|
|
||||||
stats["service"] = {
|
stats["service"] = {
|
||||||
"uptime": (int(time.time()) - stats_tracking["started"]),
|
"uptime": (int(time.time()) - stats_tracking["started"]),
|
||||||
"version": VERSION,
|
"version": VERSION,
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
import copy
|
import copy
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
|
import subprocess as sp
|
||||||
|
import json
|
||||||
import re
|
import re
|
||||||
import signal
|
import signal
|
||||||
import traceback
|
import traceback
|
||||||
@ -679,6 +681,36 @@ def escape_special_characters(path: str) -> str:
|
|||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def get_cpu_stats() -> dict[str, dict]:
|
||||||
|
"""Get cpu usages for each process id"""
|
||||||
|
usages = {}
|
||||||
|
top_command = ["top", "-b", "-n", "1"]
|
||||||
|
|
||||||
|
p = sp.run(
|
||||||
|
top_command,
|
||||||
|
encoding="ascii",
|
||||||
|
capture_output=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
if p.returncode != 0:
|
||||||
|
logger.error(p.stderr)
|
||||||
|
return usages
|
||||||
|
else:
|
||||||
|
lines = p.stdout.split("\n")
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
stats = list(filter(lambda a: a != "", line.strip().split(" ")))
|
||||||
|
try:
|
||||||
|
usages[stats[0]] = {
|
||||||
|
"cpu": stats[8],
|
||||||
|
"mem": stats[9],
|
||||||
|
}
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
|
||||||
|
return usages
|
||||||
|
|
||||||
|
|
||||||
class FrameManager(ABC):
|
class FrameManager(ABC):
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def create(self, name, size) -> AnyStr:
|
def create(self, name, size) -> AnyStr:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user