generated from mantinedev/next-pages-template
-
-
Notifications
You must be signed in to change notification settings - Fork 260
/
HealthMonitoringCpu.tsx
113 lines (108 loc) · 3.26 KB
/
HealthMonitoringCpu.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { Center, Flex, Group, HoverCard, RingProgress, Text } from '@mantine/core';
import { IconCpu } from '@tabler/icons-react';
import { useTranslation } from 'react-i18next';
const HealthMonitoringCpu = ({ info, cpuTemp, fahrenheit }: any) => {
const { t } = useTranslation('modules/health-monitoring');
const toFahrenheit = (value: number) => {
return Math.round(value * 1.8 + 32);
};
interface LoadDataItem {
label: string;
stats: number;
progress: number;
color: string;
}
const loadData = [
{
label: `${t('cpu.minute', { minute: 1 })}`,
stats: info.loadAverage['1min'],
progress: info.loadAverage['1min'],
color: 'teal',
},
{
label: `${t('cpu.minutes', { minutes: 5 })}`,
stats: info.loadAverage['5min'],
progress: info.loadAverage['5min'],
color: 'blue',
},
{
label: `${t('cpu.minutes', { minutes: 15 })}`,
stats: info.loadAverage['15min'],
progress: info.loadAverage['15min'],
color: 'red',
},
] as const;
return (
<Group position="center">
<RingProgress
roundCaps
size={120}
thickness={12}
label={
<Center style={{ flexDirection: 'column' }}>
{info.cpuUtilization.toFixed(2)}%
<HoverCard width={280} shadow="md" position="top" withinPortal>
<HoverCard.Target>
<IconCpu size={40} />
</HoverCard.Target>
<HoverCard.Dropdown>
<Text fz="lg" tt="uppercase" fw={700} c="dimmed" align="center">
{t('cpu.load')}
</Text>
<Flex
direction={{ base: 'column', sm: 'row' }}
gap={{ base: 'sm', sm: 'lg' }}
justify={{ sm: 'center' }}
>
{loadData.map((load: LoadDataItem) => (
<RingProgress
size={80}
roundCaps
thickness={8}
label={
<Text color={load.color} weight={700} align="center" size="xl">
{load.progress}
</Text>
}
sections={[{ value: load.progress, color: load.color, tooltip: load.label }]}
/>
))}
</Flex>
</HoverCard.Dropdown>
</HoverCard>
</Center>
}
sections={[
{
value: info.cpuUtilization.toFixed(2),
color: info.cpuUtilization.toFixed(2) > 70 ? 'red' : 'green',
},
]}
/>
{cpuTemp && (
<RingProgress
roundCaps
size={120}
thickness={12}
label={
<Center
style={{
flexDirection: 'column',
}}
>
{fahrenheit ? `${toFahrenheit(cpuTemp.cputemp)}°F` : `${cpuTemp.cputemp}°C`}
<IconCpu size={40} />
</Center>
}
sections={[
{
value: cpuTemp.cputemp,
color: cpuTemp.cputemp < 60 ? 'green' : 'red',
},
]}
/>
)}
</Group>
);
};
export default HealthMonitoringCpu;