Complete Docker monitoring integration with Capture API
This commit completes the Docker container monitoring feature using Capture API. Frontend changes: - Updated Infrastructure create/edit form to support Docker monitors - Conditional UI based on monitor type (hardware vs docker) - Docker-specific labels and placeholders - Capture server URL field (e.g., http://192.168.1.100:59232) - API secret field for Bearer token authentication - Enforced 30-second minimum polling interval for Docker - Conditionally hide hardware thresholds for Docker monitors - Updated useInfrastructureSubmit hook - Accept monitorType parameter (hardware or docker) - Build form with type-specific fields - Only add thresholds for hardware monitors - Submit with correct monitor type to backend - Created DockerContainersTable component - Displays all containers from Capture API response - Shows: container name, ID, status, health, image, uptime, ports - Color-coded status indicators (green=healthy, yellow=warning, red=error) - Formats uptime/downtime duration - Handles empty state gracefully - Updated Infrastructure Details page - Conditionally render Docker container table for docker monitors - Keep existing hardware metrics (gauges, charts) for hardware monitors - Hide network tab for Docker monitors (not applicable) - Display container data from latest check Implementation complete and ready for testing.
This commit is contained in:
4 files changed
+284
-51
No files matched your search
@@ -5,7 +5,7 @@ import {
|
|||||||
const useInfrastructureSubmit = () => {
|
const useInfrastructureSubmit = () => {
|
||||||
const [createMonitor, isCreating] = useCreateMonitor();
|
const [createMonitor, isCreating] = useCreateMonitor();
|
||||||
const [updateMonitor, isUpdating] = useUpdateMonitor();
|
const [updateMonitor, isUpdating] = useUpdateMonitor();
|
||||||
const buildForm = (infrastructureMonitor, https) => {
|
const buildForm = (infrastructureMonitor, https, monitorType = "hardware") => {
|
||||||
const MS_PER_MINUTE = 60000;
|
const MS_PER_MINUTE = 60000;
|
||||||
|
|
||||||
let form = {
|
let form = {
|
||||||
@@ -17,31 +17,37 @@ const useInfrastructureSubmit = () => {
|
|||||||
interval: infrastructureMonitor.interval * MS_PER_MINUTE,
|
interval: infrastructureMonitor.interval * MS_PER_MINUTE,
|
||||||
statusWindowSize: infrastructureMonitor.statusWindowSize,
|
statusWindowSize: infrastructureMonitor.statusWindowSize,
|
||||||
statusWindowThreshold: infrastructureMonitor.statusWindowThreshold,
|
statusWindowThreshold: infrastructureMonitor.statusWindowThreshold,
|
||||||
cpu: infrastructureMonitor.cpu,
|
|
||||||
...(infrastructureMonitor.cpu
|
|
||||||
? { usage_cpu: infrastructureMonitor.usage_cpu }
|
|
||||||
: {}),
|
|
||||||
memory: infrastructureMonitor.memory,
|
|
||||||
...(infrastructureMonitor.memory
|
|
||||||
? { usage_memory: infrastructureMonitor.usage_memory }
|
|
||||||
: {}),
|
|
||||||
disk: infrastructureMonitor.disk,
|
|
||||||
...(infrastructureMonitor.disk
|
|
||||||
? { usage_disk: infrastructureMonitor.usage_disk }
|
|
||||||
: {}),
|
|
||||||
temperature: infrastructureMonitor.temperature,
|
|
||||||
...(infrastructureMonitor.temperature
|
|
||||||
? { usage_temperature: infrastructureMonitor.usage_temperature }
|
|
||||||
: {}),
|
|
||||||
secret: infrastructureMonitor.secret,
|
secret: infrastructureMonitor.secret,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Only add hardware-specific thresholds for hardware monitors
|
||||||
|
if (monitorType === "hardware") {
|
||||||
|
form.cpu = infrastructureMonitor.cpu;
|
||||||
|
if (infrastructureMonitor.cpu) {
|
||||||
|
form.usage_cpu = infrastructureMonitor.usage_cpu;
|
||||||
|
}
|
||||||
|
form.memory = infrastructureMonitor.memory;
|
||||||
|
if (infrastructureMonitor.memory) {
|
||||||
|
form.usage_memory = infrastructureMonitor.usage_memory;
|
||||||
|
}
|
||||||
|
form.disk = infrastructureMonitor.disk;
|
||||||
|
if (infrastructureMonitor.disk) {
|
||||||
|
form.usage_disk = infrastructureMonitor.usage_disk;
|
||||||
|
}
|
||||||
|
form.temperature = infrastructureMonitor.temperature;
|
||||||
|
if (infrastructureMonitor.temperature) {
|
||||||
|
form.usage_temperature = infrastructureMonitor.usage_temperature;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return form;
|
return form;
|
||||||
};
|
};
|
||||||
const submitInfrastructureForm = async (
|
const submitInfrastructureForm = async (
|
||||||
infrastructureMonitor,
|
infrastructureMonitor,
|
||||||
form,
|
form,
|
||||||
isCreate,
|
isCreate,
|
||||||
monitorId
|
monitorId,
|
||||||
|
monitorType = "hardware"
|
||||||
) => {
|
) => {
|
||||||
const {
|
const {
|
||||||
cpu,
|
cpu,
|
||||||
@@ -55,20 +61,24 @@ const useInfrastructureSubmit = () => {
|
|||||||
...rest
|
...rest
|
||||||
} = form;
|
} = form;
|
||||||
|
|
||||||
const thresholds = {
|
// Only build thresholds for hardware monitors
|
||||||
...(cpu ? { usage_cpu: usage_cpu / 100 } : {}),
|
const thresholds =
|
||||||
...(memory ? { usage_memory: usage_memory / 100 } : {}),
|
monitorType === "hardware"
|
||||||
...(disk ? { usage_disk: usage_disk / 100 } : {}),
|
? {
|
||||||
...(temperature ? { usage_temperature: usage_temperature / 100 } : {}),
|
...(cpu ? { usage_cpu: usage_cpu / 100 } : {}),
|
||||||
};
|
...(memory ? { usage_memory: usage_memory / 100 } : {}),
|
||||||
|
...(disk ? { usage_disk: usage_disk / 100 } : {}),
|
||||||
|
...(temperature ? { usage_temperature: usage_temperature / 100 } : {}),
|
||||||
|
}
|
||||||
|
: {};
|
||||||
|
|
||||||
const finalForm = {
|
const finalForm = {
|
||||||
...(isCreate ? {} : { _id: monitorId }),
|
...(isCreate ? {} : { _id: monitorId }),
|
||||||
...rest,
|
...rest,
|
||||||
description: form.name,
|
description: form.name,
|
||||||
type: "hardware",
|
type: monitorType,
|
||||||
notifications: infrastructureMonitor.notifications,
|
notifications: infrastructureMonitor.notifications,
|
||||||
thresholds,
|
...(Object.keys(thresholds).length > 0 ? { thresholds } : {}),
|
||||||
};
|
};
|
||||||
// Handle create or update
|
// Handle create or update
|
||||||
isCreate
|
isCreate
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ const CreateInfrastructureMonitor = () => {
|
|||||||
const { buildForm, submitInfrastructureForm, isCreating, isUpdating } =
|
const { buildForm, submitInfrastructureForm, isCreating, isUpdating } =
|
||||||
useInfrastructureSubmit();
|
useInfrastructureSubmit();
|
||||||
|
|
||||||
const FREQUENCIES = [
|
const ALL_FREQUENCIES = [
|
||||||
{ _id: 0.25, name: t("time.fifteenSeconds") },
|
{ _id: 0.25, name: t("time.fifteenSeconds") },
|
||||||
{ _id: 0.5, name: t("time.thirtySeconds") },
|
{ _id: 0.5, name: t("time.thirtySeconds") },
|
||||||
{ _id: 1, name: t("time.oneMinute") },
|
{ _id: 1, name: t("time.oneMinute") },
|
||||||
@@ -71,6 +71,12 @@ const CreateInfrastructureMonitor = () => {
|
|||||||
{ _id: 5, name: t("time.fiveMinutes") },
|
{ _id: 5, name: t("time.fiveMinutes") },
|
||||||
{ _id: 10, name: t("time.tenMinutes") },
|
{ _id: 10, name: t("time.tenMinutes") },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Docker monitors require minimum 30 second interval
|
||||||
|
const FREQUENCIES =
|
||||||
|
monitorType === "docker"
|
||||||
|
? ALL_FREQUENCIES.filter((f) => f._id >= 0.5)
|
||||||
|
: ALL_FREQUENCIES;
|
||||||
const CRUMBS = [
|
const CRUMBS = [
|
||||||
{ name: "Infrastructure monitors", path: "/infrastructure" },
|
{ name: "Infrastructure monitors", path: "/infrastructure" },
|
||||||
...(isCreate
|
...(isCreate
|
||||||
@@ -102,12 +108,12 @@ const CreateInfrastructureMonitor = () => {
|
|||||||
// Handlers
|
// Handlers
|
||||||
const onSubmit = async (event) => {
|
const onSubmit = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const form = buildForm(infrastructureMonitor, https);
|
const form = buildForm(infrastructureMonitor, https, monitorType);
|
||||||
const error = validateForm(form);
|
const error = validateForm(form);
|
||||||
if (error) {
|
if (error) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
submitInfrastructureForm(infrastructureMonitor, form, isCreate, monitorId);
|
submitInfrastructureForm(infrastructureMonitor, form, isCreate, monitorId, monitorType);
|
||||||
};
|
};
|
||||||
|
|
||||||
const triggerUpdate = () => {
|
const triggerUpdate = () => {
|
||||||
@@ -204,15 +210,25 @@ const CreateInfrastructureMonitor = () => {
|
|||||||
{t("settingsGeneralSettings")}
|
{t("settingsGeneralSettings")}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography component="p">
|
<Typography component="p">
|
||||||
{t("infrastructureCreateGeneralSettingsDescription")}
|
{monitorType === "docker"
|
||||||
|
? "Configure your Capture server to monitor Docker containers."
|
||||||
|
: t("infrastructureCreateGeneralSettingsDescription")}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography component="p">
|
<Typography component="p">
|
||||||
{t("infrastructureServerRequirement")}{" "}
|
{monitorType === "docker" ? (
|
||||||
<Link
|
<>
|
||||||
level="primary"
|
Capture server endpoint: <code>/api/v1/metrics/docker</code>
|
||||||
url="https://github.com/bluewave-labs/checkmate-agent"
|
</>
|
||||||
label={t("common.monitoringAgentName")}
|
) : (
|
||||||
/>
|
<>
|
||||||
|
{t("infrastructureServerRequirement")}{" "}
|
||||||
|
<Link
|
||||||
|
level="primary"
|
||||||
|
url="https://github.com/bluewave-labs/checkmate-agent"
|
||||||
|
label={t("common.monitoringAgentName")}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Stack gap={theme.spacing(8)}>
|
<Stack gap={theme.spacing(8)}>
|
||||||
@@ -221,8 +237,16 @@ const CreateInfrastructureMonitor = () => {
|
|||||||
id="url"
|
id="url"
|
||||||
name="url"
|
name="url"
|
||||||
startAdornment={<HttpAdornment https={https} />}
|
startAdornment={<HttpAdornment https={https} />}
|
||||||
placeholder={"localhost:59232/api/v1/metrics"}
|
placeholder={
|
||||||
label={t("infrastructureServerUrlLabel")}
|
monitorType === "docker"
|
||||||
|
? "192.168.1.100:59232"
|
||||||
|
: "localhost:59232/api/v1/metrics"
|
||||||
|
}
|
||||||
|
label={
|
||||||
|
monitorType === "docker"
|
||||||
|
? "Capture Server URL"
|
||||||
|
: t("infrastructureServerUrlLabel")
|
||||||
|
}
|
||||||
https={https}
|
https={https}
|
||||||
value={infrastructureMonitor.url}
|
value={infrastructureMonitor.url}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
@@ -268,7 +292,12 @@ const CreateInfrastructureMonitor = () => {
|
|||||||
type="text"
|
type="text"
|
||||||
id="secret"
|
id="secret"
|
||||||
name="secret"
|
name="secret"
|
||||||
label={t("infrastructureAuthorizationSecretLabel")}
|
label={
|
||||||
|
monitorType === "docker"
|
||||||
|
? "Capture API Secret"
|
||||||
|
: t("infrastructureAuthorizationSecretLabel")
|
||||||
|
}
|
||||||
|
placeholder={monitorType === "docker" ? "Bearer token for Capture API" : ""}
|
||||||
value={infrastructureMonitor.secret}
|
value={infrastructureMonitor.secret}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
error={errors["secret"] ? true : false}
|
error={errors["secret"] ? true : false}
|
||||||
@@ -325,12 +354,14 @@ const CreateInfrastructureMonitor = () => {
|
|||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
</ConfigBox>
|
</ConfigBox>
|
||||||
<CustomAlertsSection
|
{monitorType === "hardware" && (
|
||||||
errors={errors}
|
<CustomAlertsSection
|
||||||
onChange={onChange}
|
errors={errors}
|
||||||
infrastructureMonitor={infrastructureMonitor}
|
onChange={onChange}
|
||||||
handleCheckboxChange={handleCheckboxChange}
|
infrastructureMonitor={infrastructureMonitor}
|
||||||
/>
|
handleCheckboxChange={handleCheckboxChange}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<ConfigBox>
|
<ConfigBox>
|
||||||
<Box>
|
<Box>
|
||||||
<Typography
|
<Typography
|
||||||
|
|||||||
+178
@@ -0,0 +1,178 @@
|
|||||||
|
import { Box, Stack, Typography } from "@mui/material";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import DataTable from "@/Components/v1/Table/index.jsx";
|
||||||
|
import { StatusLabel } from "@/Components/v1/Label/index.jsx";
|
||||||
|
|
||||||
|
const DockerContainersTable = ({ containers = [] }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
// Helper to format uptime
|
||||||
|
const formatUptime = (startedAt, finishedAt, running) => {
|
||||||
|
if (!running && finishedAt > 0) {
|
||||||
|
const stoppedAgo = Math.floor(Date.now() / 1000) - finishedAt;
|
||||||
|
return formatDuration(stoppedAgo) + " ago";
|
||||||
|
}
|
||||||
|
if (running && startedAt > 0) {
|
||||||
|
const uptimeSeconds = Math.floor(Date.now() / 1000) - startedAt;
|
||||||
|
return formatDuration(uptimeSeconds);
|
||||||
|
}
|
||||||
|
return "N/A";
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper to format duration
|
||||||
|
const formatDuration = (seconds) => {
|
||||||
|
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`;
|
||||||
|
if (hours > 0) return `${hours}h ${minutes}m`;
|
||||||
|
if (minutes > 0) return `${minutes}m`;
|
||||||
|
return `${seconds}s`;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper to get status color
|
||||||
|
const getStatusColor = (status, running, healthy) => {
|
||||||
|
if (status === "running" && healthy) return "success";
|
||||||
|
if (status === "running" && !healthy) return "warning";
|
||||||
|
if (status === "exited") return "error";
|
||||||
|
if (status === "paused") return "warning";
|
||||||
|
if (status === "restarting") return "warning";
|
||||||
|
return "default";
|
||||||
|
};
|
||||||
|
|
||||||
|
const headers = [
|
||||||
|
{
|
||||||
|
id: "name",
|
||||||
|
content: "Container Name",
|
||||||
|
render: (row) => (
|
||||||
|
<Box>
|
||||||
|
<Typography
|
||||||
|
variant="body2"
|
||||||
|
fontWeight={600}
|
||||||
|
>
|
||||||
|
{row.container_name || "Unnamed"}
|
||||||
|
</Typography>
|
||||||
|
<Typography
|
||||||
|
variant="caption"
|
||||||
|
color="textSecondary"
|
||||||
|
>
|
||||||
|
{row.container_id ? row.container_id.substring(0, 12) : "N/A"}
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "status",
|
||||||
|
content: "Status",
|
||||||
|
render: (row) => (
|
||||||
|
<StatusLabel
|
||||||
|
status={getStatusColor(row.status, row.running, row.health?.healthy)}
|
||||||
|
text={row.status || "unknown"}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "health",
|
||||||
|
content: "Health",
|
||||||
|
render: (row) => (
|
||||||
|
<Box>
|
||||||
|
<Typography
|
||||||
|
variant="body2"
|
||||||
|
color={row.health?.healthy ? "success.main" : "error.main"}
|
||||||
|
>
|
||||||
|
{row.health?.healthy ? "Healthy" : "Unhealthy"}
|
||||||
|
</Typography>
|
||||||
|
<Typography
|
||||||
|
variant="caption"
|
||||||
|
color="textSecondary"
|
||||||
|
>
|
||||||
|
{row.health?.source === "container_health_check" ? "HEALTHCHECK" : "State-based"}
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "image",
|
||||||
|
content: "Image",
|
||||||
|
render: (row) => (
|
||||||
|
<Typography variant="body2">{row.base_image || "N/A"}</Typography>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "uptime",
|
||||||
|
content: "Uptime",
|
||||||
|
render: (row) => (
|
||||||
|
<Typography variant="body2">
|
||||||
|
{formatUptime(row.started_at, row.finished_at, row.running)}
|
||||||
|
</Typography>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "ports",
|
||||||
|
content: "Ports",
|
||||||
|
render: (row) => (
|
||||||
|
<Box>
|
||||||
|
{row.exposed_ports && row.exposed_ports.length > 0 ? (
|
||||||
|
row.exposed_ports.map((port, idx) => (
|
||||||
|
<Typography
|
||||||
|
key={idx}
|
||||||
|
variant="caption"
|
||||||
|
sx={{ display: "block" }}
|
||||||
|
>
|
||||||
|
{port.port}/{port.protocol}
|
||||||
|
</Typography>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<Typography
|
||||||
|
variant="caption"
|
||||||
|
color="textSecondary"
|
||||||
|
>
|
||||||
|
None
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!containers || containers.length === 0) {
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
padding: theme.spacing(12),
|
||||||
|
textAlign: "center",
|
||||||
|
border: `1px solid ${theme.palette.divider}`,
|
||||||
|
borderRadius: theme.spacing(2),
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
variant="body1"
|
||||||
|
color="textSecondary"
|
||||||
|
>
|
||||||
|
No containers found
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack gap={theme.spacing(4)}>
|
||||||
|
<Typography
|
||||||
|
variant="h3"
|
||||||
|
fontWeight={600}
|
||||||
|
>
|
||||||
|
Docker Containers ({containers.length})
|
||||||
|
</Typography>
|
||||||
|
<DataTable
|
||||||
|
headers={headers}
|
||||||
|
data={containers}
|
||||||
|
config={{
|
||||||
|
emptyView: "No containers found",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DockerContainersTable;
|
||||||
@@ -8,6 +8,7 @@ import GaugeBoxes from "./Components/GaugeBoxes/index.jsx";
|
|||||||
import AreaChartBoxes from "./Components/AreaChartBoxes/index.jsx";
|
import AreaChartBoxes from "./Components/AreaChartBoxes/index.jsx";
|
||||||
import GenericFallback from "@/Components/v1/GenericFallback/index.jsx";
|
import GenericFallback from "@/Components/v1/GenericFallback/index.jsx";
|
||||||
import NetworkStats from "./Components/NetworkStats/index.jsx";
|
import NetworkStats from "./Components/NetworkStats/index.jsx";
|
||||||
|
import DockerContainersTable from "./Components/DockerContainersTable/index.jsx";
|
||||||
import CustomTabList from "@/Components/v1/Tab/index.jsx";
|
import CustomTabList from "@/Components/v1/Tab/index.jsx";
|
||||||
import TabContext from "@mui/lab/TabContext";
|
import TabContext from "@mui/lab/TabContext";
|
||||||
|
|
||||||
@@ -98,12 +99,25 @@ const InfrastructureDetails = () => {
|
|||||||
label={t("details")}
|
label={t("details")}
|
||||||
value="details"
|
value="details"
|
||||||
/>
|
/>
|
||||||
<Tab
|
{monitor?.type !== "docker" && (
|
||||||
label={t("network")}
|
<Tab
|
||||||
value="network"
|
label={t("network")}
|
||||||
/>
|
value="network"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</CustomTabList>
|
</CustomTabList>
|
||||||
{tab === "details" && (
|
{tab === "details" && monitor?.type === "docker" && (
|
||||||
|
<>
|
||||||
|
<StatusBoxes
|
||||||
|
shouldRender={!isLoading}
|
||||||
|
monitor={monitor}
|
||||||
|
/>
|
||||||
|
<DockerContainersTable
|
||||||
|
containers={monitor?.stats?.aggregateData?.latestCheck?.docker || []}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{tab === "details" && monitor?.type !== "docker" && (
|
||||||
<>
|
<>
|
||||||
<StatusBoxes
|
<StatusBoxes
|
||||||
shouldRender={!isLoading}
|
shouldRender={!isLoading}
|
||||||
@@ -125,7 +139,7 @@ const InfrastructureDetails = () => {
|
|||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{tab === "network" && (
|
{tab === "network" && monitor?.type !== "docker" && (
|
||||||
<NetworkStats
|
<NetworkStats
|
||||||
net={monitor?.stats?.aggregateData?.latestCheck?.net || []}
|
net={monitor?.stats?.aggregateData?.latestCheck?.net || []}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
|
|||||||
Reference in new issue
Block a user