mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-10 21:25:24 +03:00
Get system graphs working for inference time
This commit is contained in:
parent
b9d8cc14de
commit
8295a0d11a
@ -14,6 +14,9 @@ from frigate.types import StatsTrackingTypes
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
MAX_STATS_POINTS = 120
|
||||||
|
|
||||||
|
|
||||||
class StatsEmitter(threading.Thread):
|
class StatsEmitter(threading.Thread):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -55,7 +58,7 @@ class StatsEmitter(threading.Thread):
|
|||||||
self.config, self.stats_tracking, self.hwaccel_errors
|
self.config, self.stats_tracking, self.hwaccel_errors
|
||||||
)
|
)
|
||||||
self.stats_history.append(stats)
|
self.stats_history.append(stats)
|
||||||
self.stats_history = self.stats_history[-10:]
|
self.stats_history = self.stats_history[-MAX_STATS_POINTS:]
|
||||||
self.requestor.send_data("stats", json.dumps(stats))
|
self.requestor.send_data("stats", json.dumps(stats))
|
||||||
logger.debug("Finished stats collection")
|
logger.debug("Finished stats collection")
|
||||||
logger.info("Exiting stats emitter...")
|
logger.info("Exiting stats emitter...")
|
||||||
|
|||||||
@ -1,54 +1,92 @@
|
|||||||
|
import { Threshold } from "@/types/graph";
|
||||||
|
import { useMemo } from "react";
|
||||||
import Chart from "react-apexcharts";
|
import Chart from "react-apexcharts";
|
||||||
|
|
||||||
type SystemGraphProps = {
|
type SystemGraphProps = {
|
||||||
graphId: string;
|
graphId: string;
|
||||||
title?: string;
|
name: string;
|
||||||
unit: string;
|
unit: string;
|
||||||
|
threshold: Threshold;
|
||||||
data: ApexAxisChartSeries;
|
data: ApexAxisChartSeries;
|
||||||
};
|
};
|
||||||
export default function SystemGraph({
|
export default function SystemGraph({
|
||||||
graphId,
|
graphId,
|
||||||
title,
|
name,
|
||||||
unit,
|
unit,
|
||||||
|
threshold,
|
||||||
data,
|
data,
|
||||||
}: SystemGraphProps) {
|
}: SystemGraphProps) {
|
||||||
|
const lastValue = useMemo<number>(
|
||||||
|
// @ts-expect-error y is valid
|
||||||
|
() => data[0].data[data[0].data.length - 1]?.y ?? 0,
|
||||||
|
[data],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Chart
|
<div className="w-full flex flex-col">
|
||||||
type="bar"
|
<div className="flex items-center gap-1">
|
||||||
options={{
|
<div className="text-xs text-muted-foreground">{name}</div>
|
||||||
chart: {
|
<div className="text-xs text-primary-foreground">
|
||||||
id: graphId,
|
{lastValue}
|
||||||
selection: {
|
{unit}
|
||||||
enabled: false,
|
</div>
|
||||||
|
</div>
|
||||||
|
<Chart
|
||||||
|
type="bar"
|
||||||
|
options={{
|
||||||
|
chart: {
|
||||||
|
id: graphId,
|
||||||
|
selection: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
toolbar: {
|
||||||
|
show: false,
|
||||||
|
},
|
||||||
|
zoom: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
toolbar: {
|
colors: [
|
||||||
|
({ value }: { value: number }) => {
|
||||||
|
if (value >= threshold.error) {
|
||||||
|
return "#FA5252";
|
||||||
|
} else if (value >= threshold.warning) {
|
||||||
|
return "#aa00aa";
|
||||||
|
} else {
|
||||||
|
return "#404040";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
],
|
||||||
|
grid: {
|
||||||
show: false,
|
show: false,
|
||||||
},
|
},
|
||||||
zoom: {
|
legend: {
|
||||||
|
show: false,
|
||||||
|
},
|
||||||
|
dataLabels: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
},
|
},
|
||||||
},
|
xaxis: {
|
||||||
legend: {
|
type: "datetime",
|
||||||
show: true,
|
axisBorder: {
|
||||||
showForSingleSeries: true,
|
show: false,
|
||||||
position: "top",
|
},
|
||||||
horizontalAlign: "left",
|
axisTicks: {
|
||||||
onItemClick: {
|
show: false,
|
||||||
toggleDataSeries: true,
|
},
|
||||||
|
labels: {
|
||||||
|
format: "h:mm",
|
||||||
|
datetimeUTC: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
yaxis: {
|
||||||
dataLabels: {
|
show: false,
|
||||||
enabled: false,
|
max: lastValue * 2,
|
||||||
},
|
},
|
||||||
xaxis: {
|
}}
|
||||||
type: "datetime",
|
series={data}
|
||||||
},
|
height="120"
|
||||||
yaxis: {
|
/>
|
||||||
show: false,
|
</div>
|
||||||
},
|
|
||||||
}}
|
|
||||||
series={data}
|
|
||||||
height="120"
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import Heading from "@/components/ui/heading";
|
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
import { FrigateStats } from "@/types/stats";
|
import { FrigateStats } from "@/types/stats";
|
||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
@ -6,11 +5,17 @@ import SystemGraph from "@/components/graph/SystemGraph";
|
|||||||
import { useFrigateStats } from "@/api/ws";
|
import { useFrigateStats } from "@/api/ws";
|
||||||
import TimeAgo from "@/components/dynamic/TimeAgo";
|
import TimeAgo from "@/components/dynamic/TimeAgo";
|
||||||
import { FrigateConfig } from "@/types/frigateConfig";
|
import { FrigateConfig } from "@/types/frigateConfig";
|
||||||
|
import {
|
||||||
|
DetectorCpuThreshold,
|
||||||
|
DetectorMemThreshold,
|
||||||
|
InferenceThreshold,
|
||||||
|
} from "@/types/graph";
|
||||||
|
|
||||||
function System() {
|
function System() {
|
||||||
const { data: config } = useSWR<FrigateConfig>("config");
|
const { data: config } = useSWR<FrigateConfig>("config");
|
||||||
|
|
||||||
// stats
|
// stats
|
||||||
|
|
||||||
const { data: initialStats } = useSWR<FrigateStats[]>("stats/history", {
|
const { data: initialStats } = useSWR<FrigateStats[]>("stats/history", {
|
||||||
revalidateOnFocus: false,
|
revalidateOnFocus: false,
|
||||||
});
|
});
|
||||||
@ -42,9 +47,10 @@ function System() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setStatsHistory([...statsHistory, updatedStats]);
|
setStatsHistory([...statsHistory, updatedStats]);
|
||||||
}, [initialStats, updatedStats, statsHistory]);
|
}, [initialStats, updatedStats]);
|
||||||
|
|
||||||
// stats data pieces
|
// stats data pieces
|
||||||
|
|
||||||
const detInferenceTimeSeries = useMemo(() => {
|
const detInferenceTimeSeries = useMemo(() => {
|
||||||
if (!statsHistory) {
|
if (!statsHistory) {
|
||||||
return [];
|
return [];
|
||||||
@ -200,6 +206,10 @@ function System() {
|
|||||||
const statTime = new Date(stats.service.last_updated * 1000);
|
const statTime = new Date(stats.service.last_updated * 1000);
|
||||||
|
|
||||||
Object.entries(stats.cameras).forEach(([key, camStats]) => {
|
Object.entries(stats.cameras).forEach(([key, camStats]) => {
|
||||||
|
if (!config?.cameras[key].enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(key in series)) {
|
if (!(key in series)) {
|
||||||
const camName = key.replaceAll("_", " ");
|
const camName = key.replaceAll("_", " ");
|
||||||
series[key] = {};
|
series[key] = {};
|
||||||
@ -210,11 +220,11 @@ function System() {
|
|||||||
|
|
||||||
series[key]["ffmpeg"].data.push({
|
series[key]["ffmpeg"].data.push({
|
||||||
x: statTime,
|
x: statTime,
|
||||||
y: stats.cpu_usages[camStats.ffmpeg_pid.toString()].cpu,
|
y: stats.cpu_usages[camStats.ffmpeg_pid.toString()]?.cpu ?? 0.0,
|
||||||
});
|
});
|
||||||
series[key]["capture"].data.push({
|
series[key]["capture"].data.push({
|
||||||
x: statTime,
|
x: statTime,
|
||||||
y: stats.cpu_usages[camStats.capture_pid.toString()].cpu,
|
y: stats.cpu_usages[camStats.capture_pid?.toString()]?.cpu ?? 0,
|
||||||
});
|
});
|
||||||
series[key]["detect"].data.push({
|
series[key]["detect"].data.push({
|
||||||
x: statTime,
|
x: statTime,
|
||||||
@ -348,32 +358,45 @@ function System() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-3 gap-2">
|
<div className="mt-4 grid grid-cols-1 sm:grid-cols-3 gap-2">
|
||||||
<div className="p-2.5 bg-primary rounded-2xl flex-col">
|
<div className="p-2.5 bg-primary rounded-2xl flex-col">
|
||||||
<div>Inference Speed</div>
|
<div className="mb-5">Detector Inference Speed</div>
|
||||||
{detInferenceTimeSeries.map((series) => (
|
{detInferenceTimeSeries.map((series) => (
|
||||||
<SystemGraph
|
<SystemGraph
|
||||||
|
key={series.name}
|
||||||
graphId="detector-inference"
|
graphId="detector-inference"
|
||||||
|
name={series.name}
|
||||||
unit="ms"
|
unit="ms"
|
||||||
|
threshold={InferenceThreshold}
|
||||||
data={[series]}
|
data={[series]}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
<div className="bg-primary rounded-2xl flex-col">
|
<div className="p-2.5 bg-primary rounded-2xl flex-col">
|
||||||
<SystemGraph
|
<div className="mb-5">Detector CPU Usage</div>
|
||||||
graphId="detector-usages"
|
{detCpuSeries.map((series) => (
|
||||||
title="CPU"
|
<SystemGraph
|
||||||
unit="%"
|
key={series.name}
|
||||||
data={detCpuSeries}
|
graphId="detector-cpu-usages"
|
||||||
/>
|
unit="%"
|
||||||
|
name={series.name}
|
||||||
|
threshold={DetectorCpuThreshold}
|
||||||
|
data={[series]}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
<div className="bg-primary rounded-2xl flex-col">
|
<div className="p-2.5 bg-primary rounded-2xl flex-col">
|
||||||
<SystemGraph
|
<div className="mb-5">Detector Memory Usage</div>
|
||||||
graphId="detector-usages"
|
{detMemSeries.map((series) => (
|
||||||
title="Memory"
|
<SystemGraph
|
||||||
unit="%"
|
key={series.name}
|
||||||
data={detMemSeries}
|
graphId="detector-mem-usages"
|
||||||
/>
|
unit="%"
|
||||||
|
name={series.name}
|
||||||
|
threshold={DetectorMemThreshold}
|
||||||
|
data={[series]}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -383,6 +406,19 @@ function System() {
|
|||||||
export default System;
|
export default System;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* <div className="bg-primary rounded-2xl flex-col">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div className="bg-primary rounded-2xl flex-col">
|
||||||
|
<SystemGraph
|
||||||
|
graphId="detector-usages"
|
||||||
|
unit="%"
|
||||||
|
name={""}
|
||||||
|
threshold={InferenceThreshold}
|
||||||
|
data={detMemSeries}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
*
|
||||||
* <Heading as="h4">Detectors</Heading>
|
* <Heading as="h4">Detectors</Heading>
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-3">
|
<div className="grid grid-cols-1 sm:grid-cols-3">
|
||||||
<SystemGraph
|
<SystemGraph
|
||||||
|
|||||||
@ -7,3 +7,23 @@ export type GraphData = {
|
|||||||
name?: string;
|
name?: string;
|
||||||
data: GraphDataPoint[];
|
data: GraphDataPoint[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type Threshold = {
|
||||||
|
warning: number;
|
||||||
|
error: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const InferenceThreshold = {
|
||||||
|
warning: 50,
|
||||||
|
error: 100,
|
||||||
|
} as Threshold;
|
||||||
|
|
||||||
|
export const DetectorCpuThreshold = {
|
||||||
|
warning: 25,
|
||||||
|
error: 50,
|
||||||
|
} as Threshold;
|
||||||
|
|
||||||
|
export const DetectorMemThreshold = {
|
||||||
|
warning: 20,
|
||||||
|
error: 50,
|
||||||
|
} as Threshold;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user