Files
Homarr/src/components/modules/system/SystemModule.tsx

65 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-05-31 19:59:31 +02:00
import {
Center,
Group,
RingProgress,
Title,
useMantineTheme,
} from '@mantine/core';
2022-06-01 11:08:27 +02:00
import { IconCpu } from '@tabler/icons';
2022-05-23 09:57:49 +02:00
import { useEffect, useState } from 'react';
import axios from 'axios';
import si from 'systeminformation';
2022-05-31 19:59:31 +02:00
import { useListState } from '@mantine/hooks';
import { IModule } from '../modules';
2022-05-23 09:57:49 +02:00
export const SystemModule: IModule = {
title: 'System info',
description: 'Show the current CPU usage and memory usage',
2022-06-01 11:08:27 +02:00
icon: IconCpu,
2022-05-23 09:57:49 +02:00
component: SystemInfo,
};
interface ApiResponse {
cpu: si.Systeminformation.CpuData;
os: si.Systeminformation.OsData;
memory: si.Systeminformation.MemData;
load: si.Systeminformation.CurrentLoadData;
}
export default function SystemInfo(args: any) {
const [data, setData] = useState<ApiResponse>();
2022-05-31 19:59:31 +02:00
// Refresh data every second
2022-05-23 09:57:49 +02:00
useEffect(() => {
setInterval(() => {
axios.get('/api/modules/systeminfo').then((res) => setData(res.data));
2022-05-31 19:59:31 +02:00
}, 1000);
}, [args]);
2022-05-31 20:22:53 +02:00
// Update data every time data changes
2022-05-31 19:59:31 +02:00
const [cpuLoadHistory, cpuLoadHistoryHandlers] =
useListState<si.Systeminformation.CurrentLoadData>([]);
2022-05-31 20:22:53 +02:00
// useEffect(() => {
// }, [data]);
2022-05-31 19:59:31 +02:00
const theme = useMantineTheme();
const currentLoad = data?.load?.currentLoad ?? 0;
2022-05-23 09:57:49 +02:00
return (
<Center>
<Group p="sm" direction="column" align="center">
<Title order={3}>Current CPU load</Title>
<RingProgress
size={150}
label={<Center>{`${currentLoad.toFixed(2)}%`}</Center>}
thickness={15}
2022-05-23 09:57:49 +02:00
roundCaps
sections={[{ value: currentLoad ?? 0, color: 'cyan' }]}
2022-05-23 09:57:49 +02:00
/>
</Group>
</Center>
);
}