fix: health monitoring hotfix (#1970)

* fix cpu temp when not available, fix hover dropdown, resize progress rings.

* fix spelling
This commit is contained in:
Yossi Hillali
2024-03-18 23:53:06 +02:00
committed by GitHub
parent 5875b1b264
commit ef70e9317d
6 changed files with 77 additions and 54 deletions

View File

@@ -12,7 +12,8 @@
"cpu": { "cpu": {
"label": "CPU", "label": "CPU",
"load": "Load Average", "load": "Load Average",
"minute": "{{minute}} minute" "minute": "{{minute}} minute",
"minutes": "{{minutes}} minutes"
}, },
"memory": { "memory": {
"label": "Memory", "label": "Memory",

View File

@@ -76,51 +76,67 @@ export const openmediavaultRouter = createTRPCRouter({
input input
); );
const cookies = authResponse.headers['set-cookie'] || []; if (authResponse.data.response.sessionid) {
sessionId = cookies sessionId = authResponse.data.response.sessionid;
.find( } else {
(cookie: any) => const cookies = authResponse.headers['set-cookie'] || [];
cookie.includes('X-OPENMEDIAVAULT-SESSIONID') || sessionId = cookies
cookie.includes('OPENMEDIAVAULT-SESSIONID') .find((cookie: any) => cookie.includes('X-OPENMEDIAVAULT-SESSIONID'))
) ?.split(';')[0];
?.split(';')[0];
loginToken = cookies loginToken = cookies
.find( .find((cookie: any) => cookie.includes('X-OPENMEDIAVAULT-LOGIN'))
(cookie: any) => ?.split(';')[0];
cookie.includes('X-OPENMEDIAVAULT-LOGIN') || cookie.includes('OPENMEDIAVAULT-LOGIN') }
)
?.split(';')[0];
} }
const [systemInfoResponse, fileSystemResponse, cpuTempResponse] = await Promise.all([ const responses = await Promise.allSettled([
makeOpenMediaVaultRPCCall( makeOpenMediaVaultRPCCall(
'system', 'system',
'getInformation', 'getInformation',
{}, {},
{ Cookie: `${loginToken};${sessionId}` }, loginToken
? { Cookie: `${loginToken};${sessionId}` }
: { 'X-OPENMEDIAVAULT-SESSIONID': sessionId as string },
input input
), ),
makeOpenMediaVaultRPCCall( makeOpenMediaVaultRPCCall(
'filesystemmgmt', 'filesystemmgmt',
'enumerateMountedFilesystems', 'enumerateMountedFilesystems',
{ includeroot: true }, { includeroot: true },
{ Cookie: `${loginToken};${sessionId}` }, loginToken
? { Cookie: `${loginToken};${sessionId}` }
: { 'X-OPENMEDIAVAULT-SESSIONID': sessionId as string },
input input
), ),
makeOpenMediaVaultRPCCall( makeOpenMediaVaultRPCCall(
'cputemp', 'cputemp',
'get', 'get',
{}, {},
{ Cookie: `${loginToken};${sessionId}` }, loginToken
? { Cookie: `${loginToken};${sessionId}` }
: { 'X-OPENMEDIAVAULT-SESSIONID': sessionId as string },
input input
), ),
]); ]);
const systemInfoResponse =
responses[0].status === 'fulfilled' && responses[0].value
? responses[0].value.data?.response
: null;
const fileSystemResponse =
responses[1].status === 'fulfilled' && responses[1].value
? responses[1].value.data?.response
: null;
const cpuTempResponse =
responses[2].status === 'fulfilled' && responses[2].value
? responses[2].value.data?.response
: null;
return { return {
authenticated: authResponse ? authResponse.data.response.authenticated : true, systemInfo: systemInfoResponse,
systemInfo: systemInfoResponse?.data.response, fileSystem: fileSystemResponse,
fileSystem: fileSystemResponse?.data.response, cpuTemp: cpuTempResponse,
cpuTemp: cpuTempResponse?.data.response,
}; };
}), }),
}); });

View File

@@ -23,13 +23,13 @@ const HealthMonitoringCpu = ({ info, cpuTemp, fahrenheit }: any) => {
color: 'teal', color: 'teal',
}, },
{ {
label: `${t('cpu.minute', { minute: 5 })}`, label: `${t('cpu.minutes', { minutes: 5 })}`,
stats: info.loadAverage['5min'], stats: info.loadAverage['5min'],
progress: info.loadAverage['5min'], progress: info.loadAverage['5min'],
color: 'blue', color: 'blue',
}, },
{ {
label: `${t('cpu.minute', { minute: 15 })}`, label: `${t('cpu.minutes', { minutes: 15 })}`,
stats: info.loadAverage['15min'], stats: info.loadAverage['15min'],
progress: info.loadAverage['15min'], progress: info.loadAverage['15min'],
color: 'red', color: 'red',
@@ -40,12 +40,12 @@ const HealthMonitoringCpu = ({ info, cpuTemp, fahrenheit }: any) => {
<Group position="center"> <Group position="center">
<RingProgress <RingProgress
roundCaps roundCaps
size={140} size={120}
thickness={12} thickness={12}
label={ label={
<Center style={{ flexDirection: 'column' }}> <Center style={{ flexDirection: 'column' }}>
{info.cpuUtilization.toFixed(2)}% {info.cpuUtilization.toFixed(2)}%
<HoverCard width={280} shadow="md" position="top"> <HoverCard width={280} shadow="md" position="top" withinPortal>
<HoverCard.Target> <HoverCard.Target>
<IconCpu size={40} /> <IconCpu size={40} />
</HoverCard.Target> </HoverCard.Target>
@@ -83,27 +83,29 @@ const HealthMonitoringCpu = ({ info, cpuTemp, fahrenheit }: any) => {
}, },
]} ]}
/> />
<RingProgress {cpuTemp && (
roundCaps <RingProgress
size={140} roundCaps
thickness={12} size={120}
label={ thickness={12}
<Center label={
style={{ <Center
flexDirection: 'column', style={{
}} flexDirection: 'column',
> }}
{fahrenheit ? `${toFahrenheit(cpuTemp.cputemp)}°F` : `${cpuTemp.cputemp}°C`} >
<IconCpu size={40} /> {fahrenheit ? `${toFahrenheit(cpuTemp.cputemp)}°F` : `${cpuTemp.cputemp}°C`}
</Center> <IconCpu size={40} />
} </Center>
sections={[ }
{ sections={[
value: cpuTemp.cputemp, {
color: cpuTemp.cputemp < 60 ? 'green' : 'red', value: cpuTemp.cputemp,
}, color: cpuTemp.cputemp < 60 ? 'green' : 'red',
]} },
/> ]}
/>
)}
</Group> </Group>
); );
}; };

View File

@@ -15,6 +15,10 @@ const HealthMonitoringFileSystem = ({ fileSystem }: any) => {
available: number; available: number;
} }
const sortedFileSystem = fileSystem.slice().sort((a: FileSystemDisk, b: FileSystemDisk) => {
return a.devicename.localeCompare(b.devicename);
});
return ( return (
<Group position="center"> <Group position="center">
<Flex <Flex
@@ -22,15 +26,15 @@ const HealthMonitoringFileSystem = ({ fileSystem }: any) => {
gap={{ base: 'sm', sm: 'lg' }} gap={{ base: 'sm', sm: 'lg' }}
justify={{ sm: 'center' }} justify={{ sm: 'center' }}
> >
{fileSystem.map((disk: FileSystemDisk) => ( {sortedFileSystem.map((disk: FileSystemDisk) => (
<RingProgress <RingProgress
size={140} size={120}
roundCaps roundCaps
thickness={12} thickness={12}
label={ label={
<Center style={{ flexDirection: 'column' }}> <Center style={{ flexDirection: 'column' }}>
{disk.devicename} {disk.devicename}
<HoverCard width={280} shadow="md" position="top"> <HoverCard width={280} radius="sm" position="top-end" withinPortal>
<HoverCard.Target> <HoverCard.Target>
<IconServer size={40} /> <IconServer size={40} />
</HoverCard.Target> </HoverCard.Target>

View File

@@ -16,12 +16,12 @@ const HealthMonitoringMemory = ({ info }: any) => {
<Group position="center"> <Group position="center">
<RingProgress <RingProgress
roundCaps roundCaps
size={140} size={120}
thickness={12} thickness={12}
label={ label={
<Center style={{ flexDirection: 'column' }}> <Center style={{ flexDirection: 'column' }}>
{usedMemoryGB}GiB {usedMemoryGB}GiB
<HoverCard width={280} shadow="md" position="top"> <HoverCard width={280} shadow="md" position="top" withinPortal>
<HoverCard.Target> <HoverCard.Target>
<IconBrain size={40} /> <IconBrain size={40} />
</HoverCard.Target> </HoverCard.Target>

View File

@@ -122,7 +122,7 @@ export const useOpenmediavaultQuery = () => {
configName: configName!, configName: configName!,
}, },
{ {
staleTime: 1000 * 10, refetchInterval: 5000,
} }
); );
}; };