generated from mantinedev/next-pages-template
-
-
Notifications
You must be signed in to change notification settings - Fork 258
/
HealthMonitoringClusterDetailPopover.tsx
232 lines (219 loc) · 7.1 KB
/
HealthMonitoringClusterDetailPopover.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
import {
Badge,
Center,
Divider,
Flex,
Group,
List,
RingProgress,
Stack,
Text,
} from '@mantine/core';
import {
IconArrowNarrowDown,
IconArrowNarrowUp,
IconBrain,
IconClockHour3,
IconCpu,
IconCube,
IconDatabase,
IconDeviceLaptop,
IconHeartBolt,
IconNetwork,
IconServer,
} from '@tabler/icons-react';
import dayjs from 'dayjs';
import duration from 'dayjs/plugin/duration';
import { useTranslation } from 'react-i18next';
import { humanFileSize } from '~/tools/humanFileSize';
import { ResourceData } from '~/widgets/health-monitoring/cluster/types';
dayjs.extend(duration);
export const ResourceTypeEntryDetails = ({ entry }: { entry: ResourceData }) => {
const { t } = useTranslation('modules/health-monitoring');
return (
<Stack spacing={0}>
<Group noWrap align="start" position="apart">
<Group noWrap align="center">
<ResourceIcon entry={entry} size={35} />
<Stack spacing={0}>
<Text fw={700} size="md">
{entry.name}
</Text>
<Text color={entry.running ? 'green' : 'yellow'}>{capitalize(entry.status)}</Text>
</Stack>
</Group>
<Group align="end">
{entry.type !== 'node' && (
<Stack align="end" spacing={0}>
<Text fw={200} size="sm">
{t('cluster.popover.node')}
</Text>
<Text color="dimmed" size="xs">
{entry.node}
</Text>
</Stack>
)}
{(entry.type === 'lxc' || entry.type === 'vm') && (
<Stack align="end" spacing={0}>
<Text fw={200} size="sm">
{t('cluster.popover.vmid')}
</Text>
<Text color="dimmed" size="xs">
{entry.vmId}
</Text>
</Stack>
)}
{entry.type === 'storage' && (
<Stack align="end" spacing={0}>
<Text fw={200} size="sm">
{t('cluster.popover.plugin')}
</Text>
<Text color="dimmed" size="xs">
{entry.storagePlugin}
</Text>
</Stack>
)}
</Group>
</Group>
<Divider mt={0} mb="xs" />
{entry.type !== 'storage' && <ComputeResourceDetails entry={entry} />}
{entry.type === 'storage' && <StorageResourceDetails entry={entry} />}
</Stack>
);
};
const ComputeResourceDetails = ({ entry }: { entry: ResourceData }) => {
const { t } = useTranslation('modules/health-monitoring');
return (
<List>
<List.Item icon={<IconCpu size={16} />}>
{t('cluster.popover.cores', { maxCpu: entry.maxCpu })}
</List.Item>
<List.Item icon={<IconBrain size={16} />}>{displayMemoryText(entry)}</List.Item>
<List.Item icon={<IconDatabase size={16} />}>{displayDiskText(entry)}</List.Item>
<List.Item icon={<IconClockHour3 size={16} />}>
{t('cluster.popover.uptime', { uptime: formatUptime(entry) })}
</List.Item>
{entry.haState && (
<List.Item icon={<IconHeartBolt size={16} />}>
{t('cluster.popover.ha', { haState: capitalize(entry.haState) })}
</List.Item>
)}
<NetStats entry={entry} />
<DiskStats entry={entry} />
</List>
);
};
const StorageResourceDetails = ({ entry }: { entry: ResourceData }) => {
const storagePercent = entry.maxDisk ? (entry.disk / entry.maxDisk) * 100 : 0;
return (
<Stack spacing={0}>
<Center>
<RingProgress
roundCaps
size={100}
thickness={10}
label={<Text ta="center">{storagePercent.toFixed(1)}%</Text>}
sections={[{ value: storagePercent, color: storagePercent > 75 ? 'orange' : 'green' }]}
/>
<Group align="center" spacing={0}>
<Text>{displayDiskText(entry, false)}</Text>
</Group>
</Center>
<Flex gap="sm" mt={0} justify="end">
<StorageType entry={entry} />
</Flex>
</Stack>
);
};
const DiskStats = ({ entry }: { entry: ResourceData }) => {
if (!entry.diskWrite || !entry.diskRead) {
return null;
}
return (
<List.Item icon={<IconDatabase size={16} />}>
<Group spacing="sm">
<Group spacing={0}>
<Text>{humanFileSize(entry.diskWrite, false)}</Text>
<IconArrowNarrowDown size={14} />
</Group>
<Group spacing={0}>
<Text>{humanFileSize(entry.diskRead, false)}</Text>
<IconArrowNarrowUp size={14} />
</Group>
</Group>
</List.Item>
);
};
const NetStats = ({ entry }: { entry: ResourceData }) => {
if (!entry.netIn || !entry.netOut) {
return null;
}
return (
<List.Item icon={<IconNetwork size={16} />}>
<Group spacing="sm">
<Group spacing={0}>
<Text>{humanFileSize(entry.netIn, false)}</Text>
<IconArrowNarrowDown size={14} />
</Group>
<Group spacing={0}>
<Text>{humanFileSize(entry.netOut, false)}</Text>
<IconArrowNarrowUp size={14} />
</Group>
</Group>
</List.Item>
);
};
const StorageType = ({ entry }: { entry: ResourceData }) => {
const { t } = useTranslation('modules/health-monitoring');
if (entry.storageShared) {
return <Badge color="blue">{t('cluster.popover.sharedStorage')}</Badge>;
} else {
return <Badge color="teal">{t('cluster.popover.localStorage')}</Badge>;
}
};
const capitalize = (input: string) => {
return input[0].toUpperCase() + input.slice(1);
};
const ResourceIcon = ({ entry, size }: { entry: ResourceData; size: number }) => {
if (entry.type === 'node') {
return <IconServer size={size} />;
} else if (entry.type === 'qemu') {
return <IconDeviceLaptop size={size} />;
} else if (entry.type === 'storage') {
return <IconDatabase size={size} />;
} else {
return <IconCube size={size} />;
}
};
const displayMemoryText = (entry: ResourceData) => {
const { t } = useTranslation('modules/health-monitoring');
if (!entry.maxMem) {
return t('cluster.popover.memSize', { maxMem: humanFileSize(0, false) });
} else if (!entry.mem) {
return t('cluster.popover.memSize', { maxMem: humanFileSize(entry.maxMem, false) });
} else {
return t('cluster.popover.memRatio', {
usedMem: humanFileSize(entry.mem, false),
maxMem: humanFileSize(entry.maxMem, false),
});
}
};
const displayDiskText = (entry: ResourceData, useTrans: boolean = true) => {
const { t } = useTranslation('modules/health-monitoring');
const maxDisk = !entry.maxDisk ? humanFileSize(0, false) : humanFileSize(entry.maxDisk, false);
const disk = !entry.disk ? humanFileSize(0, false) : humanFileSize(entry.disk, false);
if (!entry.maxDisk || !entry.disk) {
return useTrans ? t('cluster.popover.diskSize', { maxDisk: maxDisk }) : maxDisk;
} else {
return useTrans
? t('cluster.popover.diskRatio', { usedDisk: disk, maxDisk: maxDisk })
: disk + ' / ' + maxDisk;
}
};
const formatUptime = (entry: ResourceData) => {
const { t } = useTranslation('modules/health-monitoring');
if (entry.uptime > 0) {
return dayjs.duration(entry.uptime * 1000).humanize();
}
return t('cluster.popover.na');
};