-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathHardwareCard.tsx
81 lines (70 loc) · 2.67 KB
/
HardwareCard.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { SSEContext } from "@/context/sse-context";
import { Spinner } from "@nextui-org/react";
import { type FC, useContext } from "react";
import { useTranslation } from "react-i18next";
const PI_NUM_CORES = 4;
const bytesToGB = (bytes: number | undefined): string => {
return bytes ? (bytes / 1024 / 1024 / 1024).toFixed(2) : "-";
};
export const HardwareCard: FC = () => {
const { t } = useTranslation();
const { hardwareInfo } = useContext(SSEContext);
if (!hardwareInfo) {
return (
<div className="bd-card mt-8 w-full transition-colors lg:ml-2 lg:mt-0 lg:w-1/2">
<h5 className="flex items-center text-lg font-bold">
{t("hardware.header")}
</h5>
<article className="flex flex-row overflow-hidden py-4">
<Spinner size="lg" />
</article>
</div>
);
}
const {
cpu_overall_percent: cpuOverallPercent,
temperatures_celsius: temperaturesCelsius,
vram_usage_percent: vramUsagePercent,
disks,
} = hardwareInfo;
const systemTemp = temperaturesCelsius?.system_temp?.toFixed(2) || "-";
const cpuPercent = cpuOverallPercent
? ((cpuOverallPercent / PI_NUM_CORES) * 100).toFixed(2)
: "-";
const mainDisk = disks?.find((disk) => disk.device === "/") || null;
const hddUsedGB = bytesToGB(mainDisk?.partition_used_bytes);
const hddTotalGB = bytesToGB(mainDisk?.partition_total_bytes);
const hddPercentUsed = mainDisk?.partition_percent
? 100.0 - mainDisk.partition_percent
: "-";
return (
<div className="bd-card mt-8 w-full transition-colors lg:ml-2 lg:mt-0 lg:w-1/2">
<h5 className="flex items-center text-lg font-bold">
{t("hardware.header")}
</h5>
<article className="flex flex-row overflow-hidden py-4">
<div className="flex w-1/2 flex-col">
<h6 className="text-sm text-gray-200">{t("hardware.cpu_load")}</h6>
<p className="flex">{cpuPercent} %</p>
</div>
<div className="flex w-1/2 flex-col">
<h6 className="text-sm text-gray-200">{t("hardware.temp")}</h6>
<p className="flex">{systemTemp} °C</p>
</div>
</article>
<article className="flex flex-row overflow-hidden py-4">
<div className="flex w-1/2 flex-col">
<h6 className="text-sm text-gray-200">{t("hardware.ram_usage")}</h6>
<p className="flex">{vramUsagePercent} %</p>
</div>
<div className="flex w-1/2 flex-col">
<h6 className="text-sm text-gray-200">{t("hardware.disk_usage")}</h6>
<p className="flex">
{hddUsedGB} / {hddTotalGB} GB ({hddPercentUsed} %)
</p>
</div>
</article>
</div>
);
};
export default HardwareCard;