Add temp to details page
This commit is contained in:
1 parent
70ff4c31fb
commit
b495579c43
1 file changed
+127
-59
@@ -17,8 +17,10 @@ import {
|
|||||||
TzTick,
|
TzTick,
|
||||||
PercentTick,
|
PercentTick,
|
||||||
InfrastructureTooltip,
|
InfrastructureTooltip,
|
||||||
|
TemperatureTooltip,
|
||||||
} from "../../../Components/Charts/Utils/chartUtils";
|
} from "../../../Components/Charts/Utils/chartUtils";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
|
import Monitors from "../../Monitors/Home";
|
||||||
|
|
||||||
const BASE_BOX_PADDING_VERTICAL = 4;
|
const BASE_BOX_PADDING_VERTICAL = 4;
|
||||||
const BASE_BOX_PADDING_HORIZONTAL = 8;
|
const BASE_BOX_PADDING_HORIZONTAL = 8;
|
||||||
@@ -205,52 +207,51 @@ const InfrastructureDetails = () => {
|
|||||||
// end height calculations
|
// end height calculations
|
||||||
|
|
||||||
const buildStatBoxes = (monitor) => {
|
const buildStatBoxes = (monitor) => {
|
||||||
let latestCheck = monitor?.checks[0] ?? null;
|
let latestCheck = monitor?.checks[monitor?.checks.length - 1] ?? null;
|
||||||
if (latestCheck === null) return [];
|
if (latestCheck === null) return [];
|
||||||
|
|
||||||
// Extract values from latest check
|
// Extract values from latest check
|
||||||
const physicalCores = latestCheck?.cpu?.physical_core ?? null;
|
const physicalCores = latestCheck?.cpu?.physical_core ?? 0;
|
||||||
const logicalCores = latestCheck?.cpu?.logical_core ?? null;
|
const logicalCores = latestCheck?.cpu?.logical_core ?? 0;
|
||||||
const cpuFrequency = latestCheck?.cpu?.frequency ?? null;
|
const cpuFrequency = latestCheck?.cpu?.frequency ?? 0;
|
||||||
const cpuTemperature =
|
const cpuTemperature =
|
||||||
latestCheck?.cpu?.temperature?.reduce((acc, curr) => acc + curr, 0) /
|
latestCheck?.cpu?.temperature?.reduce((acc, curr) => acc + curr, 0) /
|
||||||
latestCheck?.cpu?.temperature?.length ?? 0;
|
latestCheck?.cpu?.temperature?.length ?? 0;
|
||||||
const memoryTotalBytes = latestCheck?.memory?.total_bytes ?? null;
|
const memoryTotalBytes = latestCheck?.memory?.total_bytes ?? 0;
|
||||||
const diskTotalBytes = latestCheck?.disk[0]?.total_bytes ?? null;
|
const diskTotalBytes = latestCheck?.disk[0]?.total_bytes ?? 0;
|
||||||
const os = latestCheck?.host?.os ?? null;
|
const os = latestCheck?.host?.os ?? null;
|
||||||
const platform = latestCheck?.host?.platform ?? null;
|
const platform = latestCheck?.host?.platform ?? null;
|
||||||
const osPlatform = os === null && platform === null ? null : `${os} ${platform}`;
|
const osPlatform = os === null && platform === null ? null : `${os} ${platform}`;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
id: 0,
|
id: 0,
|
||||||
heading: "CPU (Physical)",
|
heading: "CPU (Physical)",
|
||||||
subHeading: physicalCores ? `${physicalCores} cores` : null,
|
subHeading: `${physicalCores} cores`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
heading: "CPU (Logical)",
|
heading: "CPU (Logical)",
|
||||||
subHeading: logicalCores ? `${logicalCores} cores` : null,
|
subHeading: `${logicalCores} cores`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 2,
|
id: 2,
|
||||||
heading: "CPU Frequency",
|
heading: "CPU Frequency",
|
||||||
subHeading: cpuFrequency ? `${(cpuFrequency / 1000).toFixed(2)} Ghz` : null,
|
subHeading: `${(cpuFrequency / 1000).toFixed(2)} Ghz`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 3,
|
id: 3,
|
||||||
heading: "Average CPU Temperature",
|
heading: "Average CPU Temperature",
|
||||||
subHeading: cpuTemperature ? `${cpuTemperature.toFixed(2)} C` : null,
|
subHeading: `${cpuTemperature.toFixed(2)} C`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 4,
|
id: 4,
|
||||||
heading: "Memory",
|
heading: "Memory",
|
||||||
subHeading: memoryTotalBytes ? formatBytes(memoryTotalBytes) : null,
|
subHeading: formatBytes(memoryTotalBytes),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 5,
|
id: 5,
|
||||||
heading: "Disk",
|
heading: "Disk",
|
||||||
subHeading: diskTotalBytes ? formatBytes(diskTotalBytes) : null,
|
subHeading: formatBytes(diskTotalBytes),
|
||||||
},
|
},
|
||||||
{ id: 6, heading: "Uptime", subHeading: "100%" },
|
{ id: 6, heading: "Uptime", subHeading: "100%" },
|
||||||
{
|
{
|
||||||
@@ -263,38 +264,38 @@ const InfrastructureDetails = () => {
|
|||||||
heading: "OS",
|
heading: "OS",
|
||||||
subHeading: osPlatform,
|
subHeading: osPlatform,
|
||||||
},
|
},
|
||||||
].filter((box) => box.subHeading !== null);
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildGaugeBoxConfigs = (monitor) => {
|
const buildGaugeBoxConfigs = (monitor) => {
|
||||||
let latestCheck = monitor?.checks[0] ?? null;
|
let latestCheck = monitor?.checks[monitor?.checks.length - 1] ?? null;
|
||||||
if (latestCheck === null) return [];
|
if (latestCheck === null) return [];
|
||||||
|
|
||||||
// Extract values from latest check
|
// Extract values from latest check
|
||||||
const memoryUsagePercent = latestCheck?.memory?.usage_percent ?? null;
|
const memoryUsagePercent = latestCheck?.memory?.usage_percent ?? 0;
|
||||||
const memoryUsedBytes = latestCheck?.memory?.used_bytes ?? null;
|
const memoryUsedBytes = latestCheck?.memory?.used_bytes ?? 0;
|
||||||
const memoryTotalBytes = latestCheck?.memory?.total_bytes ?? null;
|
const memoryTotalBytes = latestCheck?.memory?.total_bytes ?? 0;
|
||||||
const cpuUsagePercent = latestCheck?.cpu?.usage_percent ?? null;
|
const cpuUsagePercent = latestCheck?.cpu?.usage_percent ?? 0;
|
||||||
const cpuPhysicalCores = latestCheck?.cpu?.physical_core ?? null;
|
const cpuPhysicalCores = latestCheck?.cpu?.physical_core ?? 0;
|
||||||
const cpuFrequency = latestCheck?.cpu?.frequency ?? null;
|
const cpuFrequency = latestCheck?.cpu?.frequency ?? 0;
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
type: "memory",
|
type: "memory",
|
||||||
value: memoryUsagePercent ? decimalToPercentage(memoryUsagePercent) : null,
|
value: decimalToPercentage(memoryUsagePercent),
|
||||||
heading: "Memory Usage",
|
heading: "Memory Usage",
|
||||||
metricOne: "Used",
|
metricOne: "Used",
|
||||||
valueOne: memoryUsedBytes ? formatBytes(memoryUsedBytes) : null,
|
valueOne: formatBytes(memoryUsedBytes),
|
||||||
metricTwo: "Total",
|
metricTwo: "Total",
|
||||||
valueTwo: memoryTotalBytes ? formatBytes(memoryTotalBytes) : null,
|
valueTwo: formatBytes(memoryTotalBytes),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "cpu",
|
type: "cpu",
|
||||||
value: cpuUsagePercent ? decimalToPercentage(cpuUsagePercent) : null,
|
value: decimalToPercentage(cpuUsagePercent),
|
||||||
heading: "CPU Usage",
|
heading: "CPU Usage",
|
||||||
metricOne: "Cores",
|
metricOne: "Cores",
|
||||||
valueOne: cpuPhysicalCores ?? 0,
|
valueOne: cpuPhysicalCores ?? 0,
|
||||||
metricTwo: "Frequency",
|
metricTwo: "Frequency",
|
||||||
valueTwo: cpuFrequency ? `${(cpuFrequency / 1000).toFixed(2)} Ghz` : null,
|
valueTwo: `${(cpuFrequency / 1000).toFixed(2)} Ghz`,
|
||||||
},
|
},
|
||||||
...(latestCheck?.disk ?? []).map((disk, idx) => ({
|
...(latestCheck?.disk ?? []).map((disk, idx) => ({
|
||||||
type: "disk",
|
type: "disk",
|
||||||
@@ -306,48 +307,127 @@ const InfrastructureDetails = () => {
|
|||||||
metricTwo: "Total",
|
metricTwo: "Total",
|
||||||
valueTwo: formatBytes(disk.total_bytes),
|
valueTwo: formatBytes(disk.total_bytes),
|
||||||
})),
|
})),
|
||||||
].filter(
|
];
|
||||||
(box) => box.value !== null && box.valueOne !== null && box.valueTwo !== null
|
};
|
||||||
);
|
|
||||||
|
const buildTemps = (monitor) => {
|
||||||
|
let numCores = 0;
|
||||||
|
const checks = monitor?.checks ?? null;
|
||||||
|
if (checks === null) return [];
|
||||||
|
for (const check of checks) {
|
||||||
|
if (check.cpu.temperature.length > numCores) {
|
||||||
|
numCores = check.cpu.temperature.length;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (numCores === 0) return [];
|
||||||
|
|
||||||
|
const temps = monitor?.checks?.map((check) => {
|
||||||
|
if (check.cpu.temperature.length > numCores) {
|
||||||
|
numCores = check.cpu.temperature.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there's no data, set the temperature to 0
|
||||||
|
if (check.cpu.temperature.length === 0) {
|
||||||
|
check.cpu.temperature = Array(numCores).fill(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return check.cpu.temperature.reduce(
|
||||||
|
(acc, cur, idx) => {
|
||||||
|
acc[`core${idx + 1}`] = cur;
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
createdAt: check.createdAt,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
return { tempKeys: Object.keys(temps[0]).slice(1), temps };
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildAreaChartConfigs = (monitor) => {
|
const buildAreaChartConfigs = (monitor) => {
|
||||||
let latestCheck = monitor?.checks[0] ?? null;
|
let latestCheck = monitor?.checks[monitor?.checks.length - 1] ?? null;
|
||||||
if (latestCheck === null) return [];
|
if (latestCheck === null) return [];
|
||||||
const temps = monitor?.checks?.map((check) =>
|
const tempData = buildTemps(monitor);
|
||||||
check.cpu.temperature.map((temp, idx) => {
|
|
||||||
return { [`core${idx + 1}`]: temp };
|
|
||||||
})
|
|
||||||
);
|
|
||||||
console.log(temps);
|
|
||||||
console.log(latestCheck);
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
type: "memory",
|
type: "memory",
|
||||||
dataKey: latestCheck?.memory?.usage_percent ? "memory.usage_percent" : null,
|
data: monitor?.checks ?? [],
|
||||||
|
dataKeys: ["memory.usage_percent"],
|
||||||
heading: "Memory usage",
|
heading: "Memory usage",
|
||||||
strokeColor: theme.palette.primary.main,
|
strokeColor: theme.palette.primary.main,
|
||||||
|
gradientStartColor: theme.palette.primary.main,
|
||||||
yLabel: "Memory Usage",
|
yLabel: "Memory Usage",
|
||||||
yDomain: [0, 1],
|
yDomain: [0, 1],
|
||||||
|
yTick: <PercentTick />,
|
||||||
|
xTick: <TzTick />,
|
||||||
|
toolTip: (
|
||||||
|
<InfrastructureTooltip
|
||||||
|
dotColor={theme.palette.primary.main}
|
||||||
|
yKey={"memory.usage_percent"}
|
||||||
|
yLabel={"Memory Usage"}
|
||||||
|
/>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "cpu",
|
type: "cpu",
|
||||||
dataKey: latestCheck?.cpu?.usage_percent ? "cpu.usage_percent" : null,
|
data: monitor?.checks ?? [],
|
||||||
|
dataKeys: ["cpu.usage_percent"],
|
||||||
heading: "CPU usage",
|
heading: "CPU usage",
|
||||||
strokeColor: theme.palette.success.main,
|
strokeColor: theme.palette.success.main,
|
||||||
|
gradientStartColor: theme.palette.success.main,
|
||||||
yLabel: "CPU Usage",
|
yLabel: "CPU Usage",
|
||||||
yDomain: [0, 1],
|
yDomain: [0, 1],
|
||||||
|
yTick: <PercentTick />,
|
||||||
|
xTick: <TzTick />,
|
||||||
|
toolTip: (
|
||||||
|
<InfrastructureTooltip
|
||||||
|
dotColor={theme.palette.success.main}
|
||||||
|
yKey={"cpu.usage_percent"}
|
||||||
|
yLabel={"CPU Usage"}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "temperature",
|
||||||
|
data: tempData.temps,
|
||||||
|
dataKeys: tempData.tempKeys,
|
||||||
|
strokeColor: theme.palette.error.main,
|
||||||
|
gradientStartColor: theme.palette.error.main,
|
||||||
|
heading: "CPU Temperature",
|
||||||
|
yLabel: "Temperature",
|
||||||
|
xTick: <TzTick />,
|
||||||
|
yDomain: [0, 200],
|
||||||
|
toolTip: (
|
||||||
|
<TemperatureTooltip
|
||||||
|
keys={tempData.tempKeys}
|
||||||
|
dotColor={theme.palette.error.main}
|
||||||
|
/>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
...(latestCheck?.disk?.map((disk, idx) => ({
|
...(latestCheck?.disk?.map((disk, idx) => ({
|
||||||
type: "disk",
|
type: "disk",
|
||||||
|
data: monitor?.checks ?? [],
|
||||||
diskIndex: idx,
|
diskIndex: idx,
|
||||||
dataKey: `disk[${idx}].usage_percent`,
|
dataKeys: [`disk[${idx}].usage_percent`],
|
||||||
heading: `Disk${idx} usage`,
|
heading: `Disk${idx} usage`,
|
||||||
strokeColor: theme.palette.warning.main,
|
strokeColor: theme.palette.warning.main,
|
||||||
|
gradientStartColor: theme.palette.warning.main,
|
||||||
yLabel: "Disk Usage",
|
yLabel: "Disk Usage",
|
||||||
yDomain: [0, 1],
|
yDomain: [0, 1],
|
||||||
|
yTick: <PercentTick />,
|
||||||
|
xTick: <TzTick />,
|
||||||
|
toolTip: (
|
||||||
|
<InfrastructureTooltip
|
||||||
|
dotColor={theme.palette.warning.main}
|
||||||
|
yKey={`disk.usage_percent`}
|
||||||
|
yLabel={"Disc usage"}
|
||||||
|
yIdx={idx}
|
||||||
|
/>
|
||||||
|
),
|
||||||
})) || []),
|
})) || []),
|
||||||
].filter((box) => box.dataKey !== null);
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fetch data
|
// Fetch data
|
||||||
@@ -459,28 +539,16 @@ const InfrastructureDetails = () => {
|
|||||||
</Typography>
|
</Typography>
|
||||||
<AreaChart
|
<AreaChart
|
||||||
height={areaChartHeight}
|
height={areaChartHeight}
|
||||||
data={monitor?.checks ?? []}
|
data={config.data}
|
||||||
dataKeys={[config.dataKey]}
|
dataKeys={config.dataKeys}
|
||||||
xKey="createdAt"
|
xKey="createdAt"
|
||||||
yKey={config.dataKey}
|
|
||||||
yDomain={config.yDomain}
|
yDomain={config.yDomain}
|
||||||
customTooltip={({ active, payload, label }) => (
|
customTooltip={config.toolTip}
|
||||||
<InfrastructureTooltip
|
xTick={config.xTick}
|
||||||
label={label}
|
yTick={config.yTick}
|
||||||
yKey={
|
|
||||||
config.type === "disk" ? "disk.usage_percent" : config.dataKey
|
|
||||||
}
|
|
||||||
yLabel={config.yLabel}
|
|
||||||
yIdx={config.diskIndex}
|
|
||||||
active={active}
|
|
||||||
payload={payload}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
xTick={<TzTick />}
|
|
||||||
yTick={<PercentTick />}
|
|
||||||
strokeColor={config.strokeColor}
|
strokeColor={config.strokeColor}
|
||||||
gradient={true}
|
gradient={true}
|
||||||
gradientStartColor={config.strokeColor}
|
gradientStartColor={config.gradientStartColor}
|
||||||
gradientEndColor="#ffffff"
|
gradientEndColor="#ffffff"
|
||||||
/>
|
/>
|
||||||
</BaseBox>
|
</BaseBox>
|
||||||
|
|||||||
Reference in new issue
Block a user