mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-05 10:45:21 +03:00
Merge branch 'blakeblackshear:dev' into dev
This commit is contained in:
commit
a4c271e3bd
@ -12,7 +12,8 @@ apt-get -qq install --no-install-recommends -y \
|
|||||||
unzip locales tzdata libxml2 xz-utils \
|
unzip locales tzdata libxml2 xz-utils \
|
||||||
python3-pip \
|
python3-pip \
|
||||||
curl \
|
curl \
|
||||||
jq
|
jq \
|
||||||
|
nethogs
|
||||||
|
|
||||||
mkdir -p -m 600 /root/.gnupg
|
mkdir -p -m 600 /root/.gnupg
|
||||||
|
|
||||||
|
|||||||
@ -33,9 +33,6 @@ class DeepStack(DetectionApi):
|
|||||||
self.api_key = detector_config.api_key
|
self.api_key = detector_config.api_key
|
||||||
self.labels = detector_config.model.merged_labelmap
|
self.labels = detector_config.model.merged_labelmap
|
||||||
|
|
||||||
self.h = detector_config.model.height
|
|
||||||
self.w = detector_config.model.width
|
|
||||||
|
|
||||||
def get_label_index(self, label_value):
|
def get_label_index(self, label_value):
|
||||||
if label_value.lower() == "truck":
|
if label_value.lower() == "truck":
|
||||||
label_value = "car"
|
label_value = "car"
|
||||||
@ -47,6 +44,7 @@ class DeepStack(DetectionApi):
|
|||||||
def detect_raw(self, tensor_input):
|
def detect_raw(self, tensor_input):
|
||||||
image_data = np.squeeze(tensor_input).astype(np.uint8)
|
image_data = np.squeeze(tensor_input).astype(np.uint8)
|
||||||
image = Image.fromarray(image_data)
|
image = Image.fromarray(image_data)
|
||||||
|
self.w, self.h = image.size
|
||||||
with io.BytesIO() as output:
|
with io.BytesIO() as output:
|
||||||
image.save(output, format="JPEG")
|
image.save(output, format="JPEG")
|
||||||
image_bytes = output.getvalue()
|
image_bytes = output.getvalue()
|
||||||
@ -56,8 +54,11 @@ class DeepStack(DetectionApi):
|
|||||||
)
|
)
|
||||||
response_json = response.json()
|
response_json = response.json()
|
||||||
detections = np.zeros((20, 6), np.float32)
|
detections = np.zeros((20, 6), np.float32)
|
||||||
|
if response_json.get("predictions") is None:
|
||||||
|
logger.debug(f"Error in parsing response json: {response_json}")
|
||||||
|
return detections
|
||||||
|
|
||||||
for i, detection in enumerate(response_json["predictions"]):
|
for i, detection in enumerate(response_json.get("predictions")):
|
||||||
logger.debug(f"Response: {detection}")
|
logger.debug(f"Response: {detection}")
|
||||||
if detection["confidence"] < 0.4:
|
if detection["confidence"] < 0.4:
|
||||||
logger.debug(f"Break due to confidence < 0.4")
|
logger.debug(f"Break due to confidence < 0.4")
|
||||||
|
|||||||
@ -79,8 +79,8 @@ class OnvifController:
|
|||||||
try:
|
try:
|
||||||
presets: list[dict] = ptz.GetPresets({"ProfileToken": profile.token})
|
presets: list[dict] = ptz.GetPresets({"ProfileToken": profile.token})
|
||||||
except ONVIFError as e:
|
except ONVIFError as e:
|
||||||
logger.error(f"Unable to get presets from camera: {camera_name}: {e}")
|
logger.warning(f"Unable to get presets from camera: {camera_name}: {e}")
|
||||||
return False
|
presets = []
|
||||||
|
|
||||||
for preset in presets:
|
for preset in presets:
|
||||||
self.cams[camera_name]["presets"][preset["Name"].lower()] = preset["token"]
|
self.cams[camera_name]["presets"][preset["Name"].lower()] = preset["token"]
|
||||||
|
|||||||
@ -16,7 +16,7 @@ from frigate.const import DRIVER_AMD, DRIVER_ENV_VAR, RECORD_DIR, CLIPS_DIR, CAC
|
|||||||
from frigate.types import StatsTrackingTypes, CameraMetricsTypes
|
from frigate.types import StatsTrackingTypes, CameraMetricsTypes
|
||||||
from frigate.util import get_amd_gpu_stats, get_intel_gpu_stats, get_nvidia_gpu_stats
|
from frigate.util import get_amd_gpu_stats, get_intel_gpu_stats, get_nvidia_gpu_stats
|
||||||
from frigate.version import VERSION
|
from frigate.version import VERSION
|
||||||
from frigate.util import get_cpu_stats
|
from frigate.util import get_cpu_stats, get_bandwidth_stats
|
||||||
from frigate.object_detection import ObjectDetectProcess
|
from frigate.object_detection import ObjectDetectProcess
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -101,6 +101,7 @@ def get_processing_stats(
|
|||||||
[
|
[
|
||||||
asyncio.create_task(set_gpu_stats(config, stats, hwaccel_errors)),
|
asyncio.create_task(set_gpu_stats(config, stats, hwaccel_errors)),
|
||||||
asyncio.create_task(set_cpu_stats(stats)),
|
asyncio.create_task(set_cpu_stats(stats)),
|
||||||
|
asyncio.create_task(set_bandwidth_stats(stats)),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -118,6 +119,14 @@ async def set_cpu_stats(all_stats: dict[str, Any]) -> None:
|
|||||||
all_stats["cpu_usages"] = cpu_stats
|
all_stats["cpu_usages"] = cpu_stats
|
||||||
|
|
||||||
|
|
||||||
|
async def set_bandwidth_stats(all_stats: dict[str, Any]) -> None:
|
||||||
|
"""Set bandwidth from nethogs."""
|
||||||
|
bandwidth_stats = get_bandwidth_stats()
|
||||||
|
|
||||||
|
if bandwidth_stats:
|
||||||
|
all_stats["bandwidth_usages"] = bandwidth_stats
|
||||||
|
|
||||||
|
|
||||||
async def set_gpu_stats(
|
async def set_gpu_stats(
|
||||||
config: FrigateConfig, all_stats: dict[str, Any], hwaccel_errors: list[str]
|
config: FrigateConfig, all_stats: dict[str, Any], hwaccel_errors: list[str]
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|||||||
@ -800,10 +800,11 @@ def get_cpu_stats() -> dict[str, dict]:
|
|||||||
docker_memlimit = get_docker_memlimit_bytes() / 1024
|
docker_memlimit = get_docker_memlimit_bytes() / 1024
|
||||||
total_mem = os.sysconf("SC_PAGE_SIZE") * os.sysconf("SC_PHYS_PAGES") / 1024
|
total_mem = os.sysconf("SC_PAGE_SIZE") * os.sysconf("SC_PHYS_PAGES") / 1024
|
||||||
|
|
||||||
for process in psutil.process_iter(["pid", "name", "cpu_percent"]):
|
for process in psutil.process_iter(["pid", "name", "cpu_percent", "cmdline"]):
|
||||||
pid = process.info["pid"]
|
pid = process.info["pid"]
|
||||||
try:
|
try:
|
||||||
cpu_percent = process.info["cpu_percent"]
|
cpu_percent = process.info["cpu_percent"]
|
||||||
|
cmdline = process.info["cmdline"]
|
||||||
|
|
||||||
with open(f"/proc/{pid}/stat", "r") as f:
|
with open(f"/proc/{pid}/stat", "r") as f:
|
||||||
stats = f.readline().split()
|
stats = f.readline().split()
|
||||||
@ -837,6 +838,36 @@ def get_cpu_stats() -> dict[str, dict]:
|
|||||||
"cpu": str(cpu_percent),
|
"cpu": str(cpu_percent),
|
||||||
"cpu_average": str(round(cpu_average_usage, 2)),
|
"cpu_average": str(round(cpu_average_usage, 2)),
|
||||||
"mem": f"{mem_pct}",
|
"mem": f"{mem_pct}",
|
||||||
|
"cmdline": " ".join(cmdline),
|
||||||
|
}
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
|
||||||
|
return usages
|
||||||
|
|
||||||
|
|
||||||
|
def get_bandwidth_stats() -> dict[str, dict]:
|
||||||
|
"""Get bandwidth usages for each ffmpeg process id"""
|
||||||
|
usages = {}
|
||||||
|
top_command = ["nethogs", "-t", "-v0", "-c5", "-d1"]
|
||||||
|
|
||||||
|
p = sp.run(
|
||||||
|
top_command,
|
||||||
|
encoding="ascii",
|
||||||
|
capture_output=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
if p.returncode != 0:
|
||||||
|
return usages
|
||||||
|
else:
|
||||||
|
lines = p.stdout.split("\n")
|
||||||
|
for line in lines:
|
||||||
|
stats = list(filter(lambda a: a != "", line.strip().split("\t")))
|
||||||
|
try:
|
||||||
|
if re.search("^ffmpeg/([0-9]+)/", stats[0]):
|
||||||
|
process = stats[0].split("/")
|
||||||
|
usages[process[1]] = {
|
||||||
|
"bandwidth": round(float(stats[2]), 1),
|
||||||
}
|
}
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
|
|||||||
@ -27,6 +27,7 @@ export default function System() {
|
|||||||
const {
|
const {
|
||||||
cpu_usages,
|
cpu_usages,
|
||||||
gpu_usages,
|
gpu_usages,
|
||||||
|
bandwidth_usages,
|
||||||
detectors,
|
detectors,
|
||||||
service = {},
|
service = {},
|
||||||
detection_fps: _,
|
detection_fps: _,
|
||||||
@ -343,15 +344,25 @@ export default function System() {
|
|||||||
<Th>FPS</Th>
|
<Th>FPS</Th>
|
||||||
<Th>CPU %</Th>
|
<Th>CPU %</Th>
|
||||||
<Th>Memory %</Th>
|
<Th>Memory %</Th>
|
||||||
|
<Th>Network Bandwidth</Th>
|
||||||
</Tr>
|
</Tr>
|
||||||
</Thead>
|
</Thead>
|
||||||
<Tbody>
|
<Tbody>
|
||||||
<Tr key="ffmpeg" index="0">
|
<Tr key="ffmpeg" index="0">
|
||||||
<Td>ffmpeg</Td>
|
<Td>ffmpeg
|
||||||
|
<Button
|
||||||
|
className="rounded-full"
|
||||||
|
type="text"
|
||||||
|
color="gray"
|
||||||
|
aria-label={cpu_usages[cameras[camera]['ffmpeg_pid']]?.['cmdline']}
|
||||||
|
onClick={() => copy(cpu_usages[cameras[camera]['ffmpeg_pid']]?.['cmdline'])}
|
||||||
|
><About className="w-3" /></Button>
|
||||||
|
</Td>
|
||||||
<Td>{cameras[camera]['ffmpeg_pid'] || '- '}</Td>
|
<Td>{cameras[camera]['ffmpeg_pid'] || '- '}</Td>
|
||||||
<Td>{cameras[camera]['camera_fps'] || '- '}</Td>
|
<Td>{cameras[camera]['camera_fps'] || '- '}</Td>
|
||||||
<Td>{cpu_usages[cameras[camera]['ffmpeg_pid']]?.['cpu'] || '- '}%</Td>
|
<Td>{cpu_usages[cameras[camera]['ffmpeg_pid']]?.['cpu'] || '- '}%</Td>
|
||||||
<Td>{cpu_usages[cameras[camera]['ffmpeg_pid']]?.['mem'] || '- '}%</Td>
|
<Td>{cpu_usages[cameras[camera]['ffmpeg_pid']]?.['mem'] || '- '}%</Td>
|
||||||
|
<Td>{bandwidth_usages[cameras[camera]['ffmpeg_pid']]?.['bandwidth'] || '- '}KB/s</Td>
|
||||||
</Tr>
|
</Tr>
|
||||||
<Tr key="capture" index="1">
|
<Tr key="capture" index="1">
|
||||||
<Td>Capture</Td>
|
<Td>Capture</Td>
|
||||||
@ -359,6 +370,7 @@ export default function System() {
|
|||||||
<Td>{cameras[camera]['process_fps'] || '- '}</Td>
|
<Td>{cameras[camera]['process_fps'] || '- '}</Td>
|
||||||
<Td>{cpu_usages[cameras[camera]['capture_pid']]?.['cpu'] || '- '}%</Td>
|
<Td>{cpu_usages[cameras[camera]['capture_pid']]?.['cpu'] || '- '}%</Td>
|
||||||
<Td>{cpu_usages[cameras[camera]['capture_pid']]?.['mem'] || '- '}%</Td>
|
<Td>{cpu_usages[cameras[camera]['capture_pid']]?.['mem'] || '- '}%</Td>
|
||||||
|
<Td>-</Td>
|
||||||
</Tr>
|
</Tr>
|
||||||
<Tr key="detect" index="2">
|
<Tr key="detect" index="2">
|
||||||
<Td>Detect</Td>
|
<Td>Detect</Td>
|
||||||
@ -379,6 +391,7 @@ export default function System() {
|
|||||||
|
|
||||||
<Td>{cpu_usages[cameras[camera]['pid']]?.['cpu'] || '- '}%</Td>
|
<Td>{cpu_usages[cameras[camera]['pid']]?.['cpu'] || '- '}%</Td>
|
||||||
<Td>{cpu_usages[cameras[camera]['pid']]?.['mem'] || '- '}%</Td>
|
<Td>{cpu_usages[cameras[camera]['pid']]?.['mem'] || '- '}%</Td>
|
||||||
|
<Td>-</Td>
|
||||||
</Tr>
|
</Tr>
|
||||||
</Tbody>
|
</Tbody>
|
||||||
</Table>
|
</Table>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user