2021-02-16 05:10:20 +01:00
|
|
|
import { h, Fragment } from 'preact';
|
2021-02-07 22:46:05 +01:00
|
|
|
import ActivityIndicator from '../components/ActivityIndicator';
|
|
|
|
import Button from '../components/Button';
|
|
|
|
import Heading from '../components/Heading';
|
|
|
|
import Link from '../components/Link';
|
2022-11-24 03:03:20 +01:00
|
|
|
import { useWs } from '../api/ws';
|
2022-02-26 20:11:00 +01:00
|
|
|
import useSWR from 'swr';
|
2022-11-13 19:48:14 +01:00
|
|
|
import axios from 'axios';
|
2021-02-07 22:46:05 +01:00
|
|
|
import { Table, Tbody, Thead, Tr, Th, Td } from '../components/Table';
|
2022-12-07 14:36:56 +01:00
|
|
|
import { useState } from 'preact/hooks';
|
2022-11-13 19:48:14 +01:00
|
|
|
import Dialog from '../components/Dialog';
|
2023-01-27 13:20:41 +01:00
|
|
|
import TimeAgo from '../components/TimeAgo';
|
2023-01-10 13:23:04 +01:00
|
|
|
import copy from 'copy-to-clipboard';
|
2021-01-09 18:26:46 +01:00
|
|
|
|
2021-02-09 20:35:33 +01:00
|
|
|
const emptyObject = Object.freeze({});
|
|
|
|
|
2022-11-20 15:56:48 +01:00
|
|
|
export default function System() {
|
2022-11-13 19:48:14 +01:00
|
|
|
const [state, setState] = useState({ showFfprobe: false, ffprobe: '' });
|
2022-02-26 20:11:00 +01:00
|
|
|
const { data: config } = useSWR('config');
|
2021-01-26 16:04:03 +01:00
|
|
|
|
2021-02-16 05:10:20 +01:00
|
|
|
const {
|
2021-02-18 05:53:57 +01:00
|
|
|
value: { payload: stats },
|
2022-11-24 03:03:20 +01:00
|
|
|
} = useWs('stats');
|
2022-02-26 20:11:00 +01:00
|
|
|
const { data: initialStats } = useSWR('stats');
|
2021-01-09 18:26:46 +01:00
|
|
|
|
2022-11-29 02:24:20 +01:00
|
|
|
const {
|
|
|
|
cpu_usages,
|
|
|
|
gpu_usages,
|
|
|
|
detectors,
|
|
|
|
service = {},
|
|
|
|
detection_fps: _,
|
|
|
|
...cameras
|
|
|
|
} = stats || initialStats || emptyObject;
|
2021-01-18 19:49:00 +01:00
|
|
|
|
2021-02-09 20:35:33 +01:00
|
|
|
const detectorNames = Object.keys(detectors || emptyObject);
|
2022-11-29 02:24:20 +01:00
|
|
|
const gpuNames = Object.keys(gpu_usages || emptyObject);
|
2021-02-09 20:35:33 +01:00
|
|
|
const cameraNames = Object.keys(cameras || emptyObject);
|
2021-01-18 19:49:00 +01:00
|
|
|
|
2022-11-13 19:48:14 +01:00
|
|
|
const onHandleFfprobe = async (camera, e) => {
|
|
|
|
if (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
|
|
|
|
setState({ ...state, showFfprobe: true });
|
|
|
|
const response = await axios.get('ffprobe', {
|
|
|
|
params: {
|
2022-12-09 02:02:11 +01:00
|
|
|
paths: `camera:${camera}`,
|
2022-11-13 19:48:14 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (response.status === 200) {
|
2023-02-26 14:05:27 +01:00
|
|
|
setState({ ...state, showFfprobe: true, ffprobe: response.data });
|
2022-11-13 19:48:14 +01:00
|
|
|
} else {
|
2022-11-29 02:24:20 +01:00
|
|
|
setState({ ...state, showFfprobe: true, ffprobe: 'There was an error getting the ffprobe output.' });
|
2022-11-13 19:48:14 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const onCopyFfprobe = async () => {
|
2023-02-26 14:05:27 +01:00
|
|
|
copy(JSON.stringify(state.ffprobe).replace(/[\\\s]+/gi, ''));
|
2022-11-13 19:48:14 +01:00
|
|
|
setState({ ...state, ffprobe: '', showFfprobe: false });
|
|
|
|
};
|
|
|
|
|
2022-11-29 02:24:20 +01:00
|
|
|
const onHandleVainfo = async (e) => {
|
|
|
|
if (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
|
|
|
|
const response = await axios.get('vainfo');
|
|
|
|
|
|
|
|
if (response.status === 200) {
|
2023-02-26 14:05:27 +01:00
|
|
|
setState({
|
|
|
|
...state,
|
|
|
|
showVainfo: true,
|
|
|
|
vainfo: response.data,
|
|
|
|
});
|
2022-11-29 02:24:20 +01:00
|
|
|
} else {
|
|
|
|
setState({ ...state, showVainfo: true, vainfo: 'There was an error getting the vainfo output.' });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const onCopyVainfo = async () => {
|
2023-02-26 14:05:27 +01:00
|
|
|
copy(JSON.stringify(state.vainfo).replace(/[\\\s]+/gi, ''));
|
2022-11-29 02:24:20 +01:00
|
|
|
setState({ ...state, vainfo: '', showVainfo: false });
|
|
|
|
};
|
|
|
|
|
2021-02-16 05:10:20 +01:00
|
|
|
return (
|
2022-02-27 15:04:12 +01:00
|
|
|
<div className="space-y-4 p-2 px-4">
|
2023-02-16 14:50:03 +01:00
|
|
|
<div className="flex justify-between">
|
|
|
|
<Heading>
|
|
|
|
System <span className="text-sm">{service.version}</span>
|
|
|
|
</Heading>
|
|
|
|
{config && (
|
|
|
|
<Link
|
|
|
|
className="p-1 text-blue-500 hover:underline"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
2023-02-21 03:16:26 +01:00
|
|
|
href="/live/webrtc/"
|
2023-02-16 14:50:03 +01:00
|
|
|
>
|
|
|
|
go2rtc dashboard
|
|
|
|
</Link>
|
|
|
|
)}
|
|
|
|
</div>
|
2022-11-29 02:24:20 +01:00
|
|
|
|
2023-01-27 13:20:41 +01:00
|
|
|
{service.last_updated && (
|
|
|
|
<p>
|
2023-02-16 14:50:03 +01:00
|
|
|
<span>
|
|
|
|
Last refreshed: <TimeAgo time={service.last_updated * 1000} dense />
|
|
|
|
</span>
|
2023-01-27 13:20:41 +01:00
|
|
|
</p>
|
|
|
|
)}
|
|
|
|
|
2022-11-13 19:48:14 +01:00
|
|
|
{state.showFfprobe && (
|
|
|
|
<Dialog>
|
2023-02-26 14:05:27 +01:00
|
|
|
<div className="p-4 mb-2 max-h-96 whitespace-pre-line overflow-scroll">
|
2022-11-13 19:48:14 +01:00
|
|
|
<Heading size="lg">Ffprobe Output</Heading>
|
2023-02-26 14:05:27 +01:00
|
|
|
{state.ffprobe != '' ? (
|
|
|
|
<div>
|
|
|
|
{state.ffprobe.map((stream, idx) => (
|
|
|
|
<div key={idx} className="mb-2 max-h-96 whitespace-pre-line">
|
|
|
|
<div>Stream {idx}:</div>
|
|
|
|
<div className="px-2">Return Code: {stream.return_code}</div>
|
|
|
|
<br />
|
|
|
|
{stream.return_code == 0 ? (
|
|
|
|
<div>
|
|
|
|
{stream.stdout.streams.map((codec, idx) => (
|
|
|
|
<div className="px-2" key={idx}>
|
|
|
|
{codec.width ? (
|
|
|
|
<div>
|
|
|
|
<div>Video:</div>
|
|
|
|
<br />
|
|
|
|
<div>Codec: {codec.codec_long_name}</div>
|
|
|
|
<div>
|
|
|
|
Resolution: {codec.width}x{codec.height}
|
|
|
|
</div>
|
|
|
|
<div>FPS: {codec.avg_frame_rate == '0/0' ? 'Unknown' : codec.avg_frame_rate}</div>
|
|
|
|
<br />
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div>
|
|
|
|
<div>Audio:</div>
|
|
|
|
<br />
|
|
|
|
<div>Codec: {codec.codec_long_name}</div>
|
|
|
|
<br />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className="px-2">
|
|
|
|
<div>Error: {stream.stderr}</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<ActivityIndicator />
|
|
|
|
)}
|
2022-11-13 19:48:14 +01:00
|
|
|
</div>
|
|
|
|
<div className="p-2 flex justify-start flex-row-reverse space-x-2">
|
|
|
|
<Button className="ml-2" onClick={() => onCopyFfprobe()} type="text">
|
|
|
|
Copy
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
className="ml-2"
|
|
|
|
onClick={() => setState({ ...state, ffprobe: '', showFfprobe: false })}
|
|
|
|
type="text"
|
|
|
|
>
|
|
|
|
Close
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</Dialog>
|
|
|
|
)}
|
2021-01-27 01:18:45 +01:00
|
|
|
|
2022-11-29 02:24:20 +01:00
|
|
|
{state.showVainfo && (
|
|
|
|
<Dialog>
|
2023-02-26 14:05:27 +01:00
|
|
|
<div className="p-4 overflow-scroll whitespace-pre-line">
|
2022-11-29 02:24:20 +01:00
|
|
|
<Heading size="lg">Vainfo Output</Heading>
|
2022-12-09 02:02:11 +01:00
|
|
|
{state.vainfo != '' ? (
|
2023-02-26 14:05:27 +01:00
|
|
|
<div className="mb-2 max-h-96 whitespace-pre-line">
|
|
|
|
<div className="">Return Code: {state.vainfo.return_code}</div>
|
|
|
|
<br />
|
|
|
|
<div className="">Process {state.vainfo.return_code == 0 ? 'Output' : 'Error'}:</div>
|
|
|
|
<br />
|
|
|
|
<div>{state.vainfo.return_code == 0 ? state.vainfo.stdout : state.vainfo.stderr}</div>
|
|
|
|
</div>
|
2022-12-09 02:02:11 +01:00
|
|
|
) : (
|
|
|
|
<ActivityIndicator />
|
|
|
|
)}
|
2022-11-29 02:24:20 +01:00
|
|
|
</div>
|
2022-12-12 13:28:44 +01:00
|
|
|
<div className="p-2 flex justify-start flex-row-reverse space-x-2 whitespace-pre-wrap">
|
2022-11-29 02:24:20 +01:00
|
|
|
<Button className="ml-2" onClick={() => onCopyVainfo()} type="text">
|
|
|
|
Copy
|
|
|
|
</Button>
|
|
|
|
<Button className="ml-2" onClick={() => setState({ ...state, vainfo: '', showVainfo: false })} type="text">
|
|
|
|
Close
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</Dialog>
|
|
|
|
)}
|
|
|
|
|
2021-02-16 05:10:20 +01:00
|
|
|
{!detectors ? (
|
|
|
|
<div>
|
|
|
|
<ActivityIndicator />
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<Fragment>
|
2022-11-13 19:48:14 +01:00
|
|
|
<Heading size="lg">Detectors</Heading>
|
|
|
|
<div data-testid="detectors" className="grid grid-cols-1 3xl:grid-cols-3 md:grid-cols-2 gap-4">
|
|
|
|
{detectorNames.map((detector) => (
|
|
|
|
<div key={detector} className="dark:bg-gray-800 shadow-md hover:shadow-lg rounded-lg transition-shadow">
|
|
|
|
<div className="text-lg flex justify-between p-4">{detector}</div>
|
|
|
|
<div className="p-2">
|
|
|
|
<Table className="w-full">
|
|
|
|
<Thead>
|
|
|
|
<Tr>
|
|
|
|
<Th>P-ID</Th>
|
|
|
|
<Th>Inference Speed</Th>
|
2023-01-11 13:11:57 +01:00
|
|
|
<Th>CPU %</Th>
|
2023-01-12 01:11:45 +01:00
|
|
|
<Th>Memory %</Th>
|
2022-11-13 19:48:14 +01:00
|
|
|
</Tr>
|
|
|
|
</Thead>
|
|
|
|
<Tbody>
|
|
|
|
<Tr>
|
|
|
|
<Td>{detectors[detector]['pid']}</Td>
|
2023-01-11 13:11:57 +01:00
|
|
|
<Td>{detectors[detector]['inference_speed']} ms</Td>
|
|
|
|
<Td>{cpu_usages[detectors[detector]['pid']]?.['cpu'] || '- '}%</Td>
|
2023-01-12 01:11:45 +01:00
|
|
|
<Td>{cpu_usages[detectors[detector]['pid']]?.['mem'] || '- '}%</Td>
|
2022-11-13 19:48:14 +01:00
|
|
|
</Tr>
|
|
|
|
</Tbody>
|
|
|
|
</Table>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))}
|
2021-02-16 05:10:20 +01:00
|
|
|
</div>
|
2021-02-06 00:56:04 +01:00
|
|
|
|
2022-11-29 02:24:20 +01:00
|
|
|
<div className="text-lg flex justify-between p-4">
|
|
|
|
<Heading size="lg">GPUs</Heading>
|
|
|
|
<Button onClick={(e) => onHandleVainfo(e)}>vainfo</Button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{!gpu_usages ? (
|
|
|
|
<div className="p-4">
|
|
|
|
<Link href={'https://docs.frigate.video/configuration/hardware_acceleration'}>
|
|
|
|
Hardware acceleration has not been setup, see the docs to setup hardware acceleration.
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div data-testid="gpus" className="grid grid-cols-1 3xl:grid-cols-3 md:grid-cols-2 gap-4">
|
|
|
|
{gpuNames.map((gpu) => (
|
|
|
|
<div key={gpu} className="dark:bg-gray-800 shadow-md hover:shadow-lg rounded-lg transition-shadow">
|
|
|
|
<div className="text-lg flex justify-between p-4">{gpu}</div>
|
|
|
|
<div className="p-2">
|
|
|
|
{gpu_usages[gpu]['gpu'] == -1 ? (
|
|
|
|
<div className="p-4">
|
2023-02-04 15:47:27 +01:00
|
|
|
There was an error getting usage stats. This does not mean hardware acceleration is not working.
|
|
|
|
Either your GPU does not support this or Frigate does not have proper access to get statistics.
|
|
|
|
This is expected for the Home Assistant addon.
|
2022-11-29 02:24:20 +01:00
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<Table className="w-full">
|
|
|
|
<Thead>
|
|
|
|
<Tr>
|
2023-01-11 13:11:57 +01:00
|
|
|
<Th>GPU %</Th>
|
2022-11-29 02:24:20 +01:00
|
|
|
<Th>Memory %</Th>
|
|
|
|
</Tr>
|
|
|
|
</Thead>
|
|
|
|
<Tbody>
|
|
|
|
<Tr>
|
|
|
|
<Td>{gpu_usages[gpu]['gpu']}</Td>
|
|
|
|
<Td>{gpu_usages[gpu]['mem']}</Td>
|
|
|
|
</Tr>
|
|
|
|
</Tbody>
|
|
|
|
</Table>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
2022-11-13 19:48:14 +01:00
|
|
|
<Heading size="lg">Cameras</Heading>
|
2023-01-04 02:23:56 +01:00
|
|
|
{!cameras ? (
|
|
|
|
<ActivityIndicator />
|
|
|
|
) : (
|
|
|
|
<div data-testid="cameras" className="grid grid-cols-1 3xl:grid-cols-3 md:grid-cols-2 gap-4">
|
|
|
|
{cameraNames.map((camera) => (
|
|
|
|
<div key={camera} className="dark:bg-gray-800 shadow-md hover:shadow-lg rounded-lg transition-shadow">
|
|
|
|
<div className="capitalize text-lg flex justify-between p-4">
|
|
|
|
<Link href={`/cameras/${camera}`}>{camera.replaceAll('_', ' ')}</Link>
|
|
|
|
<Button onClick={(e) => onHandleFfprobe(camera, e)}>ffprobe</Button>
|
|
|
|
</div>
|
|
|
|
<div className="p-2">
|
|
|
|
<Table className="w-full">
|
|
|
|
<Thead>
|
|
|
|
<Tr>
|
|
|
|
<Th>Process</Th>
|
|
|
|
<Th>P-ID</Th>
|
2023-01-11 13:11:57 +01:00
|
|
|
<Th>FPS</Th>
|
|
|
|
<Th>CPU %</Th>
|
2023-01-04 02:23:56 +01:00
|
|
|
<Th>Memory %</Th>
|
|
|
|
</Tr>
|
|
|
|
</Thead>
|
|
|
|
<Tbody>
|
2023-01-11 13:11:57 +01:00
|
|
|
<Tr key="ffmpeg" index="0">
|
|
|
|
<Td>ffmpeg</Td>
|
|
|
|
<Td>{cameras[camera]['ffmpeg_pid'] || '- '}</Td>
|
|
|
|
<Td>{cameras[camera]['camera_fps'] || '- '}</Td>
|
|
|
|
<Td>{cpu_usages[cameras[camera]['ffmpeg_pid']]?.['cpu'] || '- '}%</Td>
|
|
|
|
<Td>{cpu_usages[cameras[camera]['ffmpeg_pid']]?.['mem'] || '- '}%</Td>
|
2023-01-14 00:14:07 +01:00
|
|
|
</Tr>
|
2023-01-11 13:11:57 +01:00
|
|
|
<Tr key="capture" index="1">
|
2023-01-04 02:23:56 +01:00
|
|
|
<Td>Capture</Td>
|
|
|
|
<Td>{cameras[camera]['capture_pid'] || '- '}</Td>
|
|
|
|
<Td>{cameras[camera]['process_fps'] || '- '}</Td>
|
|
|
|
<Td>{cpu_usages[cameras[camera]['capture_pid']]?.['cpu'] || '- '}%</Td>
|
|
|
|
<Td>{cpu_usages[cameras[camera]['capture_pid']]?.['mem'] || '- '}%</Td>
|
|
|
|
</Tr>
|
2023-01-11 13:11:57 +01:00
|
|
|
<Tr key="detect" index="2">
|
2023-01-04 02:23:56 +01:00
|
|
|
<Td>Detect</Td>
|
|
|
|
<Td>{cameras[camera]['pid'] || '- '}</Td>
|
2023-01-14 00:14:07 +01:00
|
|
|
|
2023-01-19 01:05:18 +01:00
|
|
|
{(() => {
|
2023-01-27 13:20:41 +01:00
|
|
|
if (cameras[camera]['pid'] && cameras[camera]['detection_enabled'] == 1)
|
2023-02-16 14:50:03 +01:00
|
|
|
return (
|
|
|
|
<Td>
|
|
|
|
{cameras[camera]['detection_fps']} ({cameras[camera]['skipped_fps']} skipped)
|
|
|
|
</Td>
|
|
|
|
);
|
2023-01-27 13:20:41 +01:00
|
|
|
else if (cameras[camera]['pid'] && cameras[camera]['detection_enabled'] == 0)
|
2023-02-16 14:50:03 +01:00
|
|
|
return <Td>disabled</Td>;
|
2023-01-27 13:20:41 +01:00
|
|
|
|
2023-02-16 14:50:03 +01:00
|
|
|
return <Td>- </Td>;
|
2023-01-19 01:05:18 +01:00
|
|
|
})()}
|
2023-01-14 00:14:07 +01:00
|
|
|
|
2023-01-04 02:23:56 +01:00
|
|
|
<Td>{cpu_usages[cameras[camera]['pid']]?.['cpu'] || '- '}%</Td>
|
|
|
|
<Td>{cpu_usages[cameras[camera]['pid']]?.['mem'] || '- '}%</Td>
|
|
|
|
</Tr>
|
|
|
|
</Tbody>
|
|
|
|
</Table>
|
|
|
|
</div>
|
2022-11-13 19:48:14 +01:00
|
|
|
</div>
|
2023-01-04 02:23:56 +01:00
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
)}
|
2021-02-16 05:10:20 +01:00
|
|
|
|
2022-11-20 15:56:48 +01:00
|
|
|
<p>System stats update automatically every {config.mqtt.stats_interval} seconds.</p>
|
2021-02-16 05:10:20 +01:00
|
|
|
</Fragment>
|
|
|
|
)}
|
2021-01-18 19:49:00 +01:00
|
|
|
</div>
|
|
|
|
);
|
2021-01-09 18:26:46 +01:00
|
|
|
}
|