remove extra function, add uptime percentage and percentage color

This commit is contained in:
Alex Holliday committed 2024-11-30 17:02:12 +08:00
1 parent d4312eef17
commit f0d60b737d
1 file changed
+32 -31
+32 -31
View File
@@ -126,25 +126,6 @@ function Infrastructure() {
const { determineState } = useUtils(); const { determineState } = useUtils();
const { monitors, total: totalMonitors } = monitorState; const { monitors, total: totalMonitors } = monitorState;
console.log(monitors);
const monitorsAsRows = monitors.map((monitor) => {
const processor =
((monitor.checks[0]?.cpu?.usage_frequency ?? 0) / 1000).toFixed(2) + " GHz";
const cpu = (monitor?.checks[0]?.cpu.usage_percent ?? 0) * 100;
const mem = (monitor?.checks[0]?.memory.usage_percent ?? 0) * 100;
const disk = (monitor?.checks[0]?.disk[0]?.usage_percent ?? 0) * 100;
return {
id: monitor._id,
url: monitor.url,
name: monitor.name,
status: determineState(monitor),
processor,
cpu,
mem,
disk,
};
});
function openDetails(id) { function openDetails(id) {
navigate(`/infrastructure/${id}`); navigate(`/infrastructure/${id}`);
} }
@@ -226,11 +207,29 @@ function Infrastructure() {
</TableRow> </TableRow>
</TableHead> </TableHead>
<TableBody> <TableBody>
{monitorsAsRows.map((row) => { {monitors.map((monitor) => {
const processor =
((monitor.checks[0]?.cpu?.usage_frequency ?? 0) / 1000).toFixed(2) +
" GHz";
const cpu = (monitor?.checks[0]?.cpu.usage_percent ?? 0) * 100;
const mem = (monitor?.checks[0]?.memory.usage_percent ?? 0) * 100;
const disk = (monitor?.checks[0]?.disk[0]?.usage_percent ?? 0) * 100;
const status = determineState(monitor);
const uptimePercentage = ((monitor?.uptimePercentage ?? 0) * 100)
.toFixed(2)
.toString();
const percentageColor =
monitor.uptimePercentage < 0.25
? theme.palette.percentage.uptimePoor
: monitor.uptimePercentage < 0.5
? theme.palette.percentage.uptimeFair
: monitor.uptimePercentage < 0.75
? theme.palette.percentage.uptimeGood
: theme.palette.percentage.uptimeExcellent;
return ( return (
<TableRow <TableRow
key={row.id} key={monitor._id}
onClick={() => openDetails(row.id)} onClick={() => openDetails(monitor.id)}
sx={{ sx={{
cursor: "pointer", cursor: "pointer",
"&:hover": { "&:hover": {
@@ -241,14 +240,16 @@ function Infrastructure() {
{/* TODO iterate over column and get column id, applying row[column.id] */} {/* TODO iterate over column and get column id, applying row[column.id] */}
<TableCell> <TableCell>
<Host <Host
title={row.name} title={monitor.name}
url={row.url} url={monitor.url}
percentage={uptimePercentage}
percentageColor={percentageColor}
/> />
</TableCell> </TableCell>
<TableCell align="center"> <TableCell align="center">
<StatusLabel <StatusLabel
status={row.status} status={status}
text={row.status} text={status}
/* Use capitalize inside of Status Label */ /* Use capitalize inside of Status Label */
/* Update component so we don't need to pass text and status separately*/ /* Update component so we don't need to pass text and status separately*/
customStyles={{ textTransform: "capitalize" }} customStyles={{ textTransform: "capitalize" }}
@@ -265,17 +266,17 @@ function Infrastructure() {
width={20} width={20}
height={20} height={20}
/> />
{row.processor} {processor}
</Stack> </Stack>
</TableCell> </TableCell>
<TableCell align="center"> <TableCell align="center">
<CustomGauge progress={row.cpu} /> <CustomGauge progress={cpu} />
</TableCell> </TableCell>
<TableCell align="center"> <TableCell align="center">
<CustomGauge progress={row.mem} /> <CustomGauge progress={mem} />
</TableCell> </TableCell>
<TableCell align="center"> <TableCell align="center">
<CustomGauge progress={row.disk} /> <CustomGauge progress={disk} />
</TableCell> </TableCell>
<TableCell align="center"> <TableCell align="center">
{/* Get ActionsMenu from Monitor Table and create a component */} {/* Get ActionsMenu from Monitor Table and create a component */}
@@ -287,7 +288,7 @@ function Infrastructure() {
}} }}
> >
<InfrastructureMenu <InfrastructureMenu
monitor={row} monitor={monitor}
isAdmin={isAdmin} isAdmin={isAdmin}
updateCallback={handleActionMenuDelete} updateCallback={handleActionMenuDelete}
/> />