feat: Add Proxmox LXC container monitoring support
## Summary Add support for monitoring Proxmox LXC containers through the Capture agent's /api/v1/metrics/proxmox endpoint. This feature is opt-in via a new setting in the infrastructure monitor configuration. ## Backend Changes - Add enableProxmoxContainers field to Monitor schema and types - Update networkService to conditionally fetch Proxmox metrics - Handle HTTP 207 multi-status responses and merge errors - Add containers field to Check schema for storing container data - Update validation schemas for the new setting ## Frontend Changes - Add ContainerStats component with charts and stat boxes - Add Containers tab to infrastructure monitor details (conditional) - Add enableProxmoxContainers switch in monitor create/edit form - Fix chart colors for disk I/O and network I/O to be distinct - Add dotColor2 prop to InfrastructureTooltip for multi-series charts - Add translation keys to all 16 locale files ## How It Works 1. User enables "Proxmox container monitoring" in monitor settings 2. Checkmate appends /proxmox to the metrics URL when fetching 3. Container data is displayed in a dedicated tab with: - CPU, memory, disk, swap, and uptime stat boxes - Interactive charts for CPU, memory, disk I/O, network I/O 4. Errors from Capture are merged and logged appropriately
This commit is contained in:
1 parent
173a4e17d2
commit
e9da602af6
35 files changed
+981
-64
No files matched your search
+141
@@ -0,0 +1,141 @@
|
||||
import PropTypes from "prop-types";
|
||||
import { Stack, Typography } from "@mui/material";
|
||||
import InfraAreaChart from "../AreaChartBoxes/InfraAreaChart.jsx";
|
||||
|
||||
import {
|
||||
TzTick,
|
||||
InfrastructureTooltip,
|
||||
NetworkTick,
|
||||
PercentTick,
|
||||
} from "@/Components/v1/Charts/Utils/chartUtils.jsx";
|
||||
import { useTheme } from "@emotion/react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useHardwareUtils } from "../../Hooks/useHardwareUtils.jsx";
|
||||
|
||||
const ContainerCharts = ({ containerData, dateRange }) => {
|
||||
const theme = useTheme();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { formatBytesPerSecondString } = useHardwareUtils();
|
||||
|
||||
if (!containerData?.length) {
|
||||
return <Typography>{t("noContainerStatsAvailable")}</Typography>;
|
||||
}
|
||||
|
||||
const formatPercentage = (value) => `${(value * 100).toFixed(1)}%`;
|
||||
|
||||
const configs = [
|
||||
{
|
||||
type: "container-cpu",
|
||||
data: containerData,
|
||||
dataKeys: ["cpuUsage"],
|
||||
heading: t("cpuUsage"),
|
||||
strokeColor: theme.palette.success.main,
|
||||
gradientStartColor: theme.palette.success.main,
|
||||
yLabel: t("usage"),
|
||||
xTick: <TzTick dateRange={dateRange} />,
|
||||
yTick: <PercentTick />,
|
||||
toolTip: (
|
||||
<InfrastructureTooltip
|
||||
dotColor={theme.palette.success.main}
|
||||
yKey={"cpuUsage"}
|
||||
yLabel={t("cpuUsage") + ": "}
|
||||
dateRange={dateRange}
|
||||
formatter={formatPercentage}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
type: "container-memory",
|
||||
data: containerData,
|
||||
dataKeys: ["memoryUsage"],
|
||||
heading: t("memoryUsage"),
|
||||
strokeColor: theme.palette.accent.main,
|
||||
gradientStartColor: theme.palette.accent.main,
|
||||
yLabel: t("usage"),
|
||||
xTick: <TzTick dateRange={dateRange} />,
|
||||
yTick: <PercentTick />,
|
||||
toolTip: (
|
||||
<InfrastructureTooltip
|
||||
dotColor={theme.palette.accent.main}
|
||||
yKey={"memoryUsage"}
|
||||
yLabel={t("memoryUsage") + ": "}
|
||||
dateRange={dateRange}
|
||||
formatter={formatPercentage}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
type: "container-disk-io",
|
||||
data: containerData,
|
||||
dataKeys: ["diskRead", "diskWrite"],
|
||||
heading: t("diskIO"),
|
||||
// Don't pass strokeColor - let chart use distinct colors from palette
|
||||
yLabel: t("rate"),
|
||||
xTick: <TzTick dateRange={dateRange} />,
|
||||
yTick: <NetworkTick formatter={formatBytesPerSecondString} />,
|
||||
toolTip: (
|
||||
<InfrastructureTooltip
|
||||
dotColor={"#3182bd"}
|
||||
yKey={"diskRead"}
|
||||
yLabel={t("diskRead") + ": "}
|
||||
dotColor2={"#6baed6"}
|
||||
yKey2={"diskWrite"}
|
||||
yLabel2={t("diskWrite") + ": "}
|
||||
dateRange={dateRange}
|
||||
formatter={formatBytesPerSecondString}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
type: "container-network-io",
|
||||
data: containerData,
|
||||
dataKeys: ["netIn", "netOut"],
|
||||
heading: t("networkIO"),
|
||||
// Don't pass strokeColor - let chart use distinct colors from palette
|
||||
yLabel: t("rate"),
|
||||
xTick: <TzTick dateRange={dateRange} />,
|
||||
yTick: <NetworkTick formatter={formatBytesPerSecondString} />,
|
||||
toolTip: (
|
||||
<InfrastructureTooltip
|
||||
dotColor={"#3182bd"}
|
||||
yKey={"netIn"}
|
||||
yLabel={t("networkIn") + ": "}
|
||||
dotColor2={"#6baed6"}
|
||||
yKey2={"netOut"}
|
||||
yLabel2={t("networkOut") + ": "}
|
||||
dateRange={dateRange}
|
||||
formatter={formatBytesPerSecondString}
|
||||
/>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<Stack
|
||||
direction={"row"}
|
||||
gap={theme.spacing(8)}
|
||||
flexWrap="wrap"
|
||||
sx={{
|
||||
"& > *": {
|
||||
flexBasis: `calc(50% - ${theme.spacing(8)})`,
|
||||
maxWidth: `calc(50% - ${theme.spacing(8)})`,
|
||||
},
|
||||
}}
|
||||
>
|
||||
{configs.map((config) => (
|
||||
<InfraAreaChart
|
||||
key={config.type}
|
||||
config={config}
|
||||
/>
|
||||
))}
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
|
||||
ContainerCharts.propTypes = {
|
||||
containerData: PropTypes.array.isRequired,
|
||||
dateRange: PropTypes.string.isRequired,
|
||||
};
|
||||
|
||||
export default ContainerCharts;
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
import PropTypes from "prop-types";
|
||||
import StatusBoxes from "@/Components/v1/StatusBoxes/index.jsx";
|
||||
import StatBox from "@/Components/v1/StatBox/index.jsx";
|
||||
import { Typography } from "@mui/material";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useHardwareUtils } from "../../Hooks/useHardwareUtils.jsx";
|
||||
|
||||
const formatUptime = (seconds) => {
|
||||
if (!seconds || seconds === 0) return "0s";
|
||||
|
||||
const days = Math.floor(seconds / 86400);
|
||||
const hours = Math.floor((seconds % 86400) / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
|
||||
if (days > 0) {
|
||||
return `${days}d ${hours}h`;
|
||||
} else if (hours > 0) {
|
||||
return `${hours}h ${minutes}m`;
|
||||
} else if (minutes > 0) {
|
||||
return `${minutes}m`;
|
||||
}
|
||||
return `${Math.floor(seconds)}s`;
|
||||
};
|
||||
|
||||
const formatPercentage = (value) => {
|
||||
if (value === undefined || value === null) return "0%";
|
||||
return `${(value * 100).toFixed(1)}%`;
|
||||
};
|
||||
|
||||
// Map container status to Checkmate monitor status for theming
|
||||
const containerStatusToMonitorStatus = (status) => {
|
||||
if (status === "running") return "up";
|
||||
if (status === "stopped") return "down";
|
||||
return "pending";
|
||||
};
|
||||
|
||||
const ContainerStatBoxes = ({ shouldRender, container }) => {
|
||||
const { t } = useTranslation();
|
||||
const { formatBytes } = useHardwareUtils();
|
||||
|
||||
if (!container) {
|
||||
return <Typography>{t("noContainerSelected")}</Typography>;
|
||||
}
|
||||
|
||||
const monitorStatus = containerStatusToMonitorStatus(container.status);
|
||||
|
||||
return (
|
||||
<StatusBoxes
|
||||
shouldRender={shouldRender}
|
||||
flexWrap="wrap"
|
||||
>
|
||||
<StatBox
|
||||
gradient={true}
|
||||
status={monitorStatus}
|
||||
heading={t("status")}
|
||||
subHeading={container.status || "unknown"}
|
||||
/>
|
||||
<StatBox
|
||||
heading={t("type")}
|
||||
subHeading={
|
||||
<Typography component="span">
|
||||
{(container.type || "lxc").toUpperCase()}
|
||||
</Typography>
|
||||
}
|
||||
/>
|
||||
<StatBox
|
||||
heading={t("uptime")}
|
||||
subHeading={formatUptime(container.uptime)}
|
||||
/>
|
||||
<StatBox
|
||||
heading={t("cpuUsage")}
|
||||
subHeading={
|
||||
<>
|
||||
{formatPercentage(container.cpu_usage)}
|
||||
<Typography component="span">
|
||||
({container.cpu_cores || 0} {t("cores")})
|
||||
</Typography>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
<StatBox
|
||||
heading={t("memoryUsage")}
|
||||
subHeading={
|
||||
<>
|
||||
{formatBytes(container.memory_used)}
|
||||
<Typography component="span"> / </Typography>
|
||||
{formatBytes(container.memory_total)}
|
||||
</>
|
||||
}
|
||||
/>
|
||||
<StatBox
|
||||
heading={t("diskUsage")}
|
||||
subHeading={
|
||||
<>
|
||||
{formatBytes(container.disk_used)}
|
||||
<Typography component="span"> / </Typography>
|
||||
{formatBytes(container.disk_total)}
|
||||
</>
|
||||
}
|
||||
/>
|
||||
</StatusBoxes>
|
||||
);
|
||||
};
|
||||
|
||||
ContainerStatBoxes.propTypes = {
|
||||
shouldRender: PropTypes.bool.isRequired,
|
||||
container: PropTypes.shape({
|
||||
vmid: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||
name: PropTypes.string,
|
||||
node: PropTypes.string,
|
||||
status: PropTypes.string,
|
||||
type: PropTypes.string,
|
||||
uptime: PropTypes.number,
|
||||
cpu_cores: PropTypes.number,
|
||||
cpu_usage: PropTypes.number,
|
||||
memory_used: PropTypes.number,
|
||||
memory_total: PropTypes.number,
|
||||
memory_usage: PropTypes.number,
|
||||
swap_used: PropTypes.number,
|
||||
swap_total: PropTypes.number,
|
||||
disk_used: PropTypes.number,
|
||||
disk_total: PropTypes.number,
|
||||
disk_read: PropTypes.number,
|
||||
disk_write: PropTypes.number,
|
||||
network_in: PropTypes.number,
|
||||
network_out: PropTypes.number,
|
||||
}),
|
||||
};
|
||||
|
||||
export default ContainerStatBoxes;
|
||||
@@ -0,0 +1,125 @@
|
||||
import PropTypes from "prop-types";
|
||||
import { useState, useEffect } from "react";
|
||||
import { Box, Typography } from "@mui/material";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useTheme } from "@emotion/react";
|
||||
import Select from "@/Components/v1/Inputs/Select/index.jsx";
|
||||
import ContainerStatBoxes from "./ContainerStatBoxes.jsx";
|
||||
import ContainerCharts from "./ContainerCharts.jsx";
|
||||
import MonitorTimeFrameHeader from "@/Components/v1/MonitorTimeFrameHeader/index.jsx";
|
||||
|
||||
const getAvailableContainers = (containers) => {
|
||||
return (containers || [])
|
||||
.filter((c) => c.vmid && c.name)
|
||||
.map((c) => ({
|
||||
vmid: String(c.vmid),
|
||||
name: c.name,
|
||||
node: c.node,
|
||||
status: c.status,
|
||||
type: c.type,
|
||||
}));
|
||||
};
|
||||
|
||||
const getContainerData = (checks, vmid) => {
|
||||
if (!vmid) return [];
|
||||
|
||||
return (checks || [])
|
||||
.map((check) => {
|
||||
const container = (check.containers || []).find(
|
||||
(c) => String(c.vmid) === String(vmid)
|
||||
);
|
||||
if (!container) return null;
|
||||
return {
|
||||
_id: check._id,
|
||||
cpuUsage: container.avgCpuUsage ?? 0,
|
||||
memoryUsage: container.avgMemoryUsage ?? 0,
|
||||
diskRead: container.deltaDiskRead ?? 0,
|
||||
diskWrite: container.deltaDiskWrite ?? 0,
|
||||
netIn: container.deltaNetIn ?? 0,
|
||||
netOut: container.deltaNetOut ?? 0,
|
||||
};
|
||||
})
|
||||
.filter(Boolean);
|
||||
};
|
||||
|
||||
const ContainerStats = ({ containers, checks, isLoading, dateRange, setDateRange }) => {
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
|
||||
const availableContainers = getAvailableContainers(containers);
|
||||
const [selectedContainer, setSelectedContainer] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
if (availableContainers.length > 0 && !selectedContainer) {
|
||||
setSelectedContainer(availableContainers[0].vmid);
|
||||
}
|
||||
}, [availableContainers, selectedContainer]);
|
||||
|
||||
const containerData = getContainerData(checks, selectedContainer);
|
||||
const currentContainer = containers?.find(
|
||||
(c) => String(c.vmid) === String(selectedContainer)
|
||||
);
|
||||
|
||||
if (!containers?.length) {
|
||||
return (
|
||||
<Box
|
||||
display="flex"
|
||||
justifyContent="center"
|
||||
alignItems="center"
|
||||
minHeight={200}
|
||||
>
|
||||
<Typography color={theme.palette.primary.contrastTextTertiary}>
|
||||
{t("noContainersAvailable")}
|
||||
</Typography>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<ContainerStatBoxes
|
||||
shouldRender={!isLoading}
|
||||
container={currentContainer}
|
||||
/>
|
||||
<Box
|
||||
display="flex"
|
||||
justifyContent="space-between"
|
||||
alignItems="flex-end"
|
||||
gap={theme.spacing(4)}
|
||||
>
|
||||
{availableContainers.length > 0 && (
|
||||
<Select
|
||||
name="container"
|
||||
label={t("container")}
|
||||
value={selectedContainer}
|
||||
onChange={(e) => setSelectedContainer(e.target.value)}
|
||||
items={availableContainers.map((c) => ({
|
||||
_id: c.vmid,
|
||||
name: `${c.name} (${c.vmid}) - ${c.node}`,
|
||||
}))}
|
||||
sx={{ minWidth: 250 }}
|
||||
/>
|
||||
)}
|
||||
<MonitorTimeFrameHeader
|
||||
isLoading={isLoading}
|
||||
dateRange={dateRange}
|
||||
setDateRange={setDateRange}
|
||||
/>
|
||||
</Box>
|
||||
<ContainerCharts
|
||||
containerData={containerData}
|
||||
dateRange={dateRange}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
ContainerStats.propTypes = {
|
||||
containers: PropTypes.array,
|
||||
checks: PropTypes.array,
|
||||
isLoading: PropTypes.bool.isRequired,
|
||||
dateRange: PropTypes.string.isRequired,
|
||||
setDateRange: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
export default ContainerStats;
|
||||
Reference in new issue
Block a user