Merge pull request #3906 from bluewave-labs/feat/first-class-docker-monitoring-client
feat: first class docker monitoring, Monitor and Host Details pages
This commit is contained in:
19 files changed
+838
-15
No files matched your search
@@ -83,12 +83,17 @@ export const Breadcrumb = ({
|
|||||||
const basePage = segments[0] || t("common.breadcrumbs.home");
|
const basePage = segments[0] || t("common.breadcrumbs.home");
|
||||||
|
|
||||||
const secondSegment = segments[1];
|
const secondSegment = segments[1];
|
||||||
|
const thirdSegment = segments[2];
|
||||||
const isActionPage = secondSegment && actionSegments.includes(secondSegment);
|
const isActionPage = secondSegment && actionSegments.includes(secondSegment);
|
||||||
const isDetailsPage = secondSegment && isId(secondSegment);
|
const isDetailsPage = secondSegment && isId(secondSegment);
|
||||||
const hasSubPage = isActionPage || isDetailsPage;
|
// page/section/:id routes such as docker/host/:monitorId
|
||||||
|
const isSectionDetailsPage = Boolean(
|
||||||
|
secondSegment && !isId(secondSegment) && thirdSegment && isId(thirdSegment)
|
||||||
|
);
|
||||||
|
const hasSubPage = isActionPage || isDetailsPage || isSectionDetailsPage;
|
||||||
|
|
||||||
const getSubPageLabel = (): string => {
|
const getSubPageLabel = (): string => {
|
||||||
if (isActionPage) {
|
if (isActionPage || isSectionDetailsPage) {
|
||||||
return secondSegment.charAt(0).toUpperCase() + secondSegment.slice(1);
|
return secondSegment.charAt(0).toUpperCase() + secondSegment.slice(1);
|
||||||
}
|
}
|
||||||
return t("common.breadcrumbs.details");
|
return t("common.breadcrumbs.details");
|
||||||
|
|||||||
@@ -1,12 +1,19 @@
|
|||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import { BaseBox } from "@/Components/design-elements";
|
import { BaseBox } from "@/Components/design-elements";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
|
||||||
import type { MonitorStatus } from "@/Types/Monitor";
|
import type { MonitorStatus } from "@/Types/Monitor";
|
||||||
import type { SxProps } from "@mui/material/styles";
|
import type { SxProps } from "@mui/material/styles";
|
||||||
import { getStatusPalette, getValuePalette } from "@/Utils/MonitorUtils";
|
import {
|
||||||
|
getDockerStatePalette,
|
||||||
|
getStatusPalette,
|
||||||
|
getValuePalette,
|
||||||
|
} from "@/Utils/MonitorUtils";
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import type { DockerContainerState } from "@/Types/Check";
|
||||||
|
import { SPACING } from "@/Utils/Theme/constants";
|
||||||
|
|
||||||
export const ValueTypes = ["positive", "negative", "neutral"] as const;
|
export const ValueTypes = ["positive", "negative", "neutral"] as const;
|
||||||
export type ValueType = (typeof ValueTypes)[number];
|
export type ValueType = (typeof ValueTypes)[number];
|
||||||
@@ -110,3 +117,36 @@ export const ColoredLabel = ({ text, color }: { text: string; color: string }) =
|
|||||||
</BaseBox>
|
</BaseBox>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const DockerStateLabel = ({
|
||||||
|
state,
|
||||||
|
name,
|
||||||
|
image,
|
||||||
|
}: {
|
||||||
|
state: DockerContainerState;
|
||||||
|
name: string;
|
||||||
|
image: string;
|
||||||
|
}) => {
|
||||||
|
const palette = getDockerStatePalette(state);
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
gap={SPACING.LG}
|
||||||
|
alignItems={"center"}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
width={7}
|
||||||
|
height={7}
|
||||||
|
bgcolor={theme.palette[palette].light}
|
||||||
|
borderRadius="50%"
|
||||||
|
marginRight="5px"
|
||||||
|
/>
|
||||||
|
<Stack>
|
||||||
|
<Typography>{name}</Typography>
|
||||||
|
<Typography variant="body2">{image}</Typography>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -9,12 +9,11 @@ import type { Tag } from "@/Types/Tag";
|
|||||||
import { Typography, useTheme } from "@mui/material";
|
import { Typography, useTheme } from "@mui/material";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
const types = ["http", "ping", "port", "docker", "game", "grpc", "websocket"];
|
const types = ["http", "ping", "port", "game", "grpc", "websocket"];
|
||||||
const typeDisplayNames: Record<string, string> = {
|
const typeDisplayNames: Record<string, string> = {
|
||||||
http: "HTTP",
|
http: "HTTP",
|
||||||
ping: "Ping",
|
ping: "Ping",
|
||||||
port: "Port",
|
port: "Port",
|
||||||
docker: "Docker",
|
|
||||||
game: "Game",
|
game: "Game",
|
||||||
grpc: "gRPC",
|
grpc: "gRPC",
|
||||||
websocket: "WebSocket",
|
websocket: "WebSocket",
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import {
|
|||||||
Users,
|
Users,
|
||||||
Tag,
|
Tag,
|
||||||
Waypoints,
|
Waypoints,
|
||||||
|
Container,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
export const getMenu = (t: Function) => {
|
export const getMenu = (t: Function) => {
|
||||||
return [
|
return [
|
||||||
@@ -40,6 +41,11 @@ export const getMenu = (t: Function) => {
|
|||||||
path: "infrastructure",
|
path: "infrastructure",
|
||||||
icon: <Icon icon={Link} />,
|
icon: <Icon icon={Link} />,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: t("components.sidebar.menu.docker"),
|
||||||
|
path: "docker",
|
||||||
|
icon: <Icon icon={Container} />,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ type TableName =
|
|||||||
| "maintenance"
|
| "maintenance"
|
||||||
| "infrastructure"
|
| "infrastructure"
|
||||||
| "logs"
|
| "logs"
|
||||||
| "pagespeed";
|
| "pagespeed"
|
||||||
|
| "docker";
|
||||||
|
|
||||||
interface TableState {
|
interface TableState {
|
||||||
rowsPerPage: number;
|
rowsPerPage: number;
|
||||||
@@ -24,6 +25,7 @@ interface UIState {
|
|||||||
team: TableState;
|
team: TableState;
|
||||||
maintenance: TableState;
|
maintenance: TableState;
|
||||||
infrastructure: TableState;
|
infrastructure: TableState;
|
||||||
|
docker: TableState;
|
||||||
logs: TableState;
|
logs: TableState;
|
||||||
sidebar: SidebarState;
|
sidebar: SidebarState;
|
||||||
mode: ThemeMode;
|
mode: ThemeMode;
|
||||||
@@ -56,6 +58,9 @@ const initialState: UIState = {
|
|||||||
infrastructure: {
|
infrastructure: {
|
||||||
rowsPerPage: 5,
|
rowsPerPage: 5,
|
||||||
},
|
},
|
||||||
|
docker: {
|
||||||
|
rowsPerPage: 5,
|
||||||
|
},
|
||||||
logs: {
|
logs: {
|
||||||
rowsPerPage: 15,
|
rowsPerPage: 15,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
const DockerDetailsPage = () => {
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DockerDetailsPage;
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
import { DockerStateLabel, Table } from "@/Components/design-elements";
|
||||||
|
// Hooks
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||||
|
import { useTheme } from "@mui/material/styles";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
|
// Types
|
||||||
|
import type { Header } from "@/Components/design-elements/Table";
|
||||||
|
import type { DockerContainerInfo } from "@/Types/Check";
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
import { formatPercentage } from "@/Utils/FormatUtils";
|
||||||
|
|
||||||
|
interface DockerContainersTableProps {
|
||||||
|
containers: DockerContainerInfo[];
|
||||||
|
onRowClick?: (container: DockerContainerInfo) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const DockerContainersTable = ({ containers }: DockerContainersTableProps) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const theme = useTheme();
|
||||||
|
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const getHeaders = () => {
|
||||||
|
// const renderSortIcon = (isActive: boolean) => (
|
||||||
|
// <Box
|
||||||
|
// width={16}
|
||||||
|
// display="inline-flex"
|
||||||
|
// justifyContent="center"
|
||||||
|
// >
|
||||||
|
// {isActive ? (
|
||||||
|
// sortOrder === "asc" ? (
|
||||||
|
// <ArrowUp size={16} />
|
||||||
|
// ) : (
|
||||||
|
// <ArrowDown size={16} />
|
||||||
|
// )
|
||||||
|
// ) : null}
|
||||||
|
// </Box>
|
||||||
|
// );
|
||||||
|
const headers: Header<DockerContainerInfo>[] = [
|
||||||
|
{
|
||||||
|
id: "container",
|
||||||
|
content: t("pages.docker.host.table.headers.container"),
|
||||||
|
render: (row) => {
|
||||||
|
return (
|
||||||
|
<DockerStateLabel
|
||||||
|
state={row.state}
|
||||||
|
name={row.name}
|
||||||
|
image={row.image}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "status",
|
||||||
|
content: t("common.table.headers.status"),
|
||||||
|
render: (row) => {
|
||||||
|
return <Typography>{row.state}</Typography>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "health",
|
||||||
|
content: t("pages.docker.host.table.headers.health"),
|
||||||
|
render: (row) => {
|
||||||
|
return <Typography>{row.health}</Typography>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "cpu",
|
||||||
|
content: t("pages.docker.host.table.headers.cpu"),
|
||||||
|
render: (row) => {
|
||||||
|
return <Typography>{formatPercentage(row.cpuPct ?? 0)}</Typography>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "memory",
|
||||||
|
content: t("pages.docker.host.table.headers.memory"),
|
||||||
|
render: (row) => {
|
||||||
|
return <Typography>{formatPercentage(row.memoryPct ?? 0)}</Typography>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "restarts",
|
||||||
|
content: t("pages.docker.host.table.headers.restarts"),
|
||||||
|
render: (row) => {
|
||||||
|
return <Typography>{row.restartCount}</Typography>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
return headers;
|
||||||
|
};
|
||||||
|
|
||||||
|
let headers = getHeaders();
|
||||||
|
|
||||||
|
if (isSmall) {
|
||||||
|
headers = headers.filter((h) => h.id !== "histogram");
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(JSON.stringify(containers, null, 2));
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Table
|
||||||
|
headers={headers}
|
||||||
|
data={containers}
|
||||||
|
onRowClick={(row) => {
|
||||||
|
navigate(`/docker/container/${row.id}`);
|
||||||
|
}}
|
||||||
|
// getRowSx={(row) => ({
|
||||||
|
// backgroundColor: isRowSelected(row.id)
|
||||||
|
// ? theme.palette.action.selected
|
||||||
|
// : "inherit",
|
||||||
|
// })}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
import { StatBox } from "@/Components/design-elements";
|
||||||
|
|
||||||
|
// Types
|
||||||
|
import type { DockerStats } from "@/Types/Monitor";
|
||||||
|
|
||||||
|
// Hooks
|
||||||
|
import { useTheme } from "@mui/material";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
|
||||||
|
export const DockerStatusBoxes = ({ stats }: { stats: DockerStats | undefined }) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
if (!stats) return null;
|
||||||
|
|
||||||
|
const { total, running, stopped, unhealthy } = stats.latest?.summary ?? {};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
gap={theme.spacing(8)}
|
||||||
|
flexWrap={"wrap"}
|
||||||
|
>
|
||||||
|
<StatBox
|
||||||
|
title={t("pages.docker.host.statBoxes.containers")}
|
||||||
|
subtitle={String(total)}
|
||||||
|
/>
|
||||||
|
<StatBox
|
||||||
|
title={t("pages.docker.host.statBoxes.running")}
|
||||||
|
subtitle={String(running)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<StatBox
|
||||||
|
title={t("pages.docker.host.statBoxes.stopped")}
|
||||||
|
subtitle={String(stopped)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<StatBox
|
||||||
|
title={t("pages.docker.host.statBoxes.unhealthy")}
|
||||||
|
subtitle={String(unhealthy)}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import { BasePage } from "@/Components/design-elements";
|
||||||
|
import { HeaderMonitorControls, MonitorStatBoxes } from "@/Components/monitors";
|
||||||
|
import { DockerStatusBoxes } from "@/Pages/Docker/HostDetails/Components/StatBoxes";
|
||||||
|
|
||||||
|
// Types
|
||||||
|
import type { DockerDetailsResponse } from "@/Types/Monitor";
|
||||||
|
|
||||||
|
// Hooks
|
||||||
|
import { useGet } from "@/Hooks/UseApi";
|
||||||
|
import { useIsAdmin } from "@/Hooks/useIsAdmin";
|
||||||
|
import { useParams } from "react-router-dom";
|
||||||
|
import { DockerContainersTable } from "@/Pages/Docker/HostDetails/Components/DockerContainersTable";
|
||||||
|
|
||||||
|
const DockerHostDetailsPage = () => {
|
||||||
|
const { monitorId } = useParams<{ monitorId: string }>();
|
||||||
|
const isAdmin = useIsAdmin();
|
||||||
|
|
||||||
|
// The containers list renders the latest check only, so no date range is
|
||||||
|
// offered; the endpoint's dateRange param only shapes the aggregate buckets.
|
||||||
|
const monitorDetailsUrl = monitorId ? `/monitors/docker/details/${monitorId}` : null;
|
||||||
|
|
||||||
|
const { data: monitorDetailsData, refetch: refetchMonitor } =
|
||||||
|
useGet<DockerDetailsResponse>(
|
||||||
|
monitorDetailsUrl,
|
||||||
|
{},
|
||||||
|
{ refreshInterval: 10000, keepPreviousData: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
const monitor = monitorDetailsData?.monitor;
|
||||||
|
const monitorStats = monitorDetailsData?.monitorStats ?? null;
|
||||||
|
const stats = monitorDetailsData?.stats;
|
||||||
|
const containers = stats?.latest?.containers ?? [];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<BasePage>
|
||||||
|
<HeaderMonitorControls
|
||||||
|
path="docker"
|
||||||
|
monitor={monitor}
|
||||||
|
isAdmin={isAdmin}
|
||||||
|
refetch={refetchMonitor}
|
||||||
|
/>
|
||||||
|
<MonitorStatBoxes
|
||||||
|
monitor={monitor}
|
||||||
|
monitorStats={monitorStats}
|
||||||
|
/>
|
||||||
|
<DockerStatusBoxes stats={stats} />
|
||||||
|
<DockerContainersTable containers={containers} />
|
||||||
|
</BasePage>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DockerHostDetailsPage;
|
||||||
@@ -0,0 +1,347 @@
|
|||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
Pagination,
|
||||||
|
StatusLabel,
|
||||||
|
ColoredLabel,
|
||||||
|
} from "@/Components/design-elements";
|
||||||
|
import { SPACING } from "@/Utils/Theme/constants";
|
||||||
|
import type { Header } from "@/Components/design-elements/Table";
|
||||||
|
import { ActionsMenu, type ActionMenuItem } from "@/Components/actions-menu";
|
||||||
|
import { ArrowUp, ArrowDown } from "lucide-react";
|
||||||
|
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||||
|
import { useTheme } from "@mui/material/styles";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { usePost } from "@/Hooks/UseApi";
|
||||||
|
|
||||||
|
import type { Monitor } from "@/Types/Monitor";
|
||||||
|
import type { Tag } from "@/Types/Tag";
|
||||||
|
import type { DockerContainerSummary } from "@/Types/Check";
|
||||||
|
import { Checkbox } from "@/Components/inputs";
|
||||||
|
|
||||||
|
const summaryOf = (monitor: Monitor): DockerContainerSummary | undefined => {
|
||||||
|
const recentChecks = monitor.recentChecks ?? [];
|
||||||
|
return recentChecks[recentChecks.length - 1]?.containerSummary;
|
||||||
|
};
|
||||||
|
|
||||||
|
interface DockerMonitorsTableProps {
|
||||||
|
monitors: Monitor[];
|
||||||
|
tags: Tag[];
|
||||||
|
refetch: () => void;
|
||||||
|
setSelectedMonitor: (monitor: Monitor | null) => void;
|
||||||
|
sortField: string;
|
||||||
|
setSortField: (field: string) => void;
|
||||||
|
sortOrder: "asc" | "desc";
|
||||||
|
setSortOrder: (order: "asc" | "desc") => void;
|
||||||
|
count: number;
|
||||||
|
page: number;
|
||||||
|
setPage: (page: number) => void;
|
||||||
|
rowsPerPage: number;
|
||||||
|
setRowsPerPage: (rowsPerPage: number) => void;
|
||||||
|
selectedRows?: string[];
|
||||||
|
onSelectionChange?: (selected: string[]) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const DockerMonitorsTable = ({
|
||||||
|
monitors,
|
||||||
|
tags,
|
||||||
|
refetch,
|
||||||
|
setSelectedMonitor,
|
||||||
|
sortField,
|
||||||
|
setSortField,
|
||||||
|
sortOrder,
|
||||||
|
setSortOrder,
|
||||||
|
count,
|
||||||
|
page,
|
||||||
|
setPage,
|
||||||
|
rowsPerPage,
|
||||||
|
setRowsPerPage,
|
||||||
|
selectedRows = [],
|
||||||
|
onSelectionChange,
|
||||||
|
}: DockerMonitorsTableProps) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const theme = useTheme();
|
||||||
|
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const { post } = usePost<Record<string, never>, Monitor>();
|
||||||
|
|
||||||
|
const selectedSet = new Set(selectedRows);
|
||||||
|
const isAllSelected =
|
||||||
|
monitors.length > 0 && monitors.every((m) => selectedSet.has(m.id));
|
||||||
|
const isSomeSelected = selectedRows.length > 0 && !isAllSelected;
|
||||||
|
|
||||||
|
const handleSelectAll = (checked: boolean) => {
|
||||||
|
onSelectionChange?.(checked ? monitors.map((m) => m.id) : []);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSelectRow = (id: string, checked: boolean) => {
|
||||||
|
if (!onSelectionChange) return;
|
||||||
|
onSelectionChange(
|
||||||
|
checked ? [...selectedRows, id] : selectedRows.filter((rowId) => rowId !== id)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const isRowSelected = (id: string) => selectedSet.has(id);
|
||||||
|
|
||||||
|
const handlePageChange = (
|
||||||
|
_e: React.MouseEvent<HTMLButtonElement> | null,
|
||||||
|
newPage: number
|
||||||
|
) => {
|
||||||
|
setPage(newPage);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRowsPerPageChange = (
|
||||||
|
e: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>
|
||||||
|
) => {
|
||||||
|
const value = Number(e.target.value);
|
||||||
|
setPage(0);
|
||||||
|
setRowsPerPage(value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSort = (e: React.MouseEvent, field: string) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
if (sortField === field) {
|
||||||
|
const newOrder = sortOrder === "asc" ? "desc" : "asc";
|
||||||
|
setSortOrder(newOrder);
|
||||||
|
} else {
|
||||||
|
setSortField(field);
|
||||||
|
setSortOrder("asc");
|
||||||
|
}
|
||||||
|
refetch();
|
||||||
|
};
|
||||||
|
|
||||||
|
const getActions = (monitor: Monitor): ActionMenuItem[] => {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
label: t("pages.common.monitors.actions.details"),
|
||||||
|
action: () => {
|
||||||
|
navigate(`${monitor.id}`);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
label: t("pages.common.monitors.actions.incidents"),
|
||||||
|
action: () => {
|
||||||
|
navigate(`/incidents?monitorId=${monitor.id}`);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 4,
|
||||||
|
label: t("pages.common.monitors.actions.configure"),
|
||||||
|
action: () => {
|
||||||
|
navigate(`/docker/configure/${monitor.id}`);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 6,
|
||||||
|
label:
|
||||||
|
monitor.isActive === false
|
||||||
|
? t("common.buttons.resume")
|
||||||
|
: t("common.buttons.pause"),
|
||||||
|
action: async () => {
|
||||||
|
await post(`/monitors/pause/${monitor.id}`, {});
|
||||||
|
refetch();
|
||||||
|
},
|
||||||
|
closeMenu: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 7,
|
||||||
|
label: (
|
||||||
|
<Typography color={theme.palette.error.main}>
|
||||||
|
{t("common.buttons.delete")}
|
||||||
|
</Typography>
|
||||||
|
),
|
||||||
|
action: () => {
|
||||||
|
setSelectedMonitor(monitor);
|
||||||
|
},
|
||||||
|
closeMenu: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
const getHeaders = () => {
|
||||||
|
const renderSortIcon = (isActive: boolean) => (
|
||||||
|
<Box
|
||||||
|
width={16}
|
||||||
|
display="inline-flex"
|
||||||
|
justifyContent="center"
|
||||||
|
>
|
||||||
|
{isActive ? (
|
||||||
|
sortOrder === "asc" ? (
|
||||||
|
<ArrowUp size={16} />
|
||||||
|
) : (
|
||||||
|
<ArrowDown size={16} />
|
||||||
|
)
|
||||||
|
) : null}
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
const headers: Header<Monitor>[] = [
|
||||||
|
{
|
||||||
|
id: "selection",
|
||||||
|
content: (
|
||||||
|
<Checkbox
|
||||||
|
aria-label={t("pages.common.monitors.actions.selectAll")}
|
||||||
|
indeterminate={isSomeSelected}
|
||||||
|
checked={isAllSelected}
|
||||||
|
onChange={(e) => handleSelectAll(e.target.checked)}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
hideMobileLabel: true,
|
||||||
|
render: (row) => (
|
||||||
|
<Checkbox
|
||||||
|
aria-label={t("pages.common.monitors.actions.selectMonitor", {
|
||||||
|
name: row.name,
|
||||||
|
})}
|
||||||
|
checked={isRowSelected(row.id)}
|
||||||
|
onChange={(e) => {
|
||||||
|
handleSelectRow(row.id, e.target.checked);
|
||||||
|
}}
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
onClick: (e) => e?.stopPropagation(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "name",
|
||||||
|
align: "left",
|
||||||
|
mobileLabel: t("pages.docker.table.headers.host"),
|
||||||
|
content: (
|
||||||
|
<Typography
|
||||||
|
component="div"
|
||||||
|
display="inline-flex"
|
||||||
|
alignItems="center"
|
||||||
|
gap={theme.spacing(4)}
|
||||||
|
onClick={(e) => handleSort(e, "name")}
|
||||||
|
sx={{ cursor: "pointer" }}
|
||||||
|
>
|
||||||
|
{t("pages.docker.table.headers.host")}
|
||||||
|
{renderSortIcon(sortField === "name")}
|
||||||
|
</Typography>
|
||||||
|
),
|
||||||
|
render: (row) => {
|
||||||
|
return (
|
||||||
|
<Stack>
|
||||||
|
<Typography variant="body2">{row.name}</Typography>
|
||||||
|
<Typography
|
||||||
|
variant="caption"
|
||||||
|
color={theme.palette.text.secondary}
|
||||||
|
>
|
||||||
|
{row.url}
|
||||||
|
</Typography>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "status",
|
||||||
|
mobileLabel: t("common.table.headers.status"),
|
||||||
|
content: (
|
||||||
|
<Stack
|
||||||
|
gap={theme.spacing(4)}
|
||||||
|
direction={"row"}
|
||||||
|
justifyContent={"center"}
|
||||||
|
alignItems={"center"}
|
||||||
|
onClick={(e) => handleSort(e, "status")}
|
||||||
|
sx={{ cursor: "pointer" }}
|
||||||
|
>
|
||||||
|
<Box width={theme.spacing(8)} />
|
||||||
|
{t("common.table.headers.status")}
|
||||||
|
{renderSortIcon(sortField === "status")}
|
||||||
|
</Stack>
|
||||||
|
),
|
||||||
|
render: (row) => {
|
||||||
|
return <StatusLabel status={row.status} />;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "containers",
|
||||||
|
content: t("pages.docker.table.headers.containers"),
|
||||||
|
render: (row) => {
|
||||||
|
const summary = summaryOf(row);
|
||||||
|
return (
|
||||||
|
<Typography variant="body2">
|
||||||
|
{summary
|
||||||
|
? t("pages.docker.table.containersRunning", {
|
||||||
|
running: summary.running,
|
||||||
|
total: summary.total,
|
||||||
|
})
|
||||||
|
: "—"}
|
||||||
|
</Typography>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "tags",
|
||||||
|
content: t("common.table.headers.tags"),
|
||||||
|
render: (row) => {
|
||||||
|
if (row.tags.length === 0) return "-";
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
justifyContent={"center"}
|
||||||
|
direction={isSmall ? "column" : "row"}
|
||||||
|
gap={theme.spacing(SPACING.LG)}
|
||||||
|
>
|
||||||
|
{row.tags.map((tagId) => {
|
||||||
|
const fullTag = tags.find((t) => t.id === tagId);
|
||||||
|
if (!fullTag) return null;
|
||||||
|
return (
|
||||||
|
<ColoredLabel
|
||||||
|
key={fullTag.id}
|
||||||
|
text={fullTag.name}
|
||||||
|
color={fullTag.color}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
content: t("common.table.headers.actions"),
|
||||||
|
render: (row) => {
|
||||||
|
return <ActionsMenu items={getActions(row)} />;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
return headers;
|
||||||
|
};
|
||||||
|
|
||||||
|
let headers = getHeaders();
|
||||||
|
|
||||||
|
if (isSmall) {
|
||||||
|
headers = headers.filter((h) => h.id !== "histogram");
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Table
|
||||||
|
headers={headers}
|
||||||
|
data={monitors}
|
||||||
|
onRowClick={(row) => {
|
||||||
|
navigate(`/docker/host/${row.id}`);
|
||||||
|
}}
|
||||||
|
getRowSx={(row) => ({
|
||||||
|
backgroundColor: isRowSelected(row.id)
|
||||||
|
? theme.palette.action.selected
|
||||||
|
: "inherit",
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
<Pagination
|
||||||
|
component="div"
|
||||||
|
count={count}
|
||||||
|
page={page}
|
||||||
|
rowsPerPage={rowsPerPage}
|
||||||
|
onPageChange={handlePageChange}
|
||||||
|
onRowsPerPageChange={handleRowsPerPageChange}
|
||||||
|
itemsOnPage={monitors.length}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
import { MonitorListPage } from "@/Components/monitors";
|
||||||
|
import { DockerMonitorsTable } from "@/Pages/Docker/Monitors/Components/DockerMonitorsTable";
|
||||||
|
import { useMonitorListController } from "@/Hooks/useMonitorListController";
|
||||||
|
|
||||||
|
const DockerMonitorsPage = () => {
|
||||||
|
const c = useMonitorListController({
|
||||||
|
types: ["docker"],
|
||||||
|
checksLimit: 25,
|
||||||
|
refreshInterval: 5000,
|
||||||
|
rowsPerPageTable: "docker",
|
||||||
|
rowsPerPageDefault: 10,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<MonitorListPage
|
||||||
|
headerKey="docker"
|
||||||
|
page="docker"
|
||||||
|
actionLink="/docker/create"
|
||||||
|
controller={c}
|
||||||
|
bulkActions
|
||||||
|
showTypeFilter={false}
|
||||||
|
>
|
||||||
|
<DockerMonitorsTable
|
||||||
|
monitors={c.monitors || []}
|
||||||
|
tags={c.tags || []}
|
||||||
|
refetch={c.refetch}
|
||||||
|
setSelectedMonitor={c.setSelectedMonitor}
|
||||||
|
count={c.count || 0}
|
||||||
|
page={c.page}
|
||||||
|
setPage={c.setPage}
|
||||||
|
rowsPerPage={c.rowsPerPage}
|
||||||
|
sortField={c.sortField}
|
||||||
|
setSortField={c.setSortField}
|
||||||
|
sortOrder={c.sortOrder}
|
||||||
|
setSortOrder={c.setSortOrder}
|
||||||
|
setRowsPerPage={c.handleSetRowsPerPage}
|
||||||
|
selectedRows={c.selectedRows}
|
||||||
|
onSelectionChange={c.setSelectedRows}
|
||||||
|
/>
|
||||||
|
</MonitorListPage>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DockerMonitorsPage;
|
||||||
@@ -20,6 +20,11 @@ import PageSpeedDetails from "@/Pages/PageSpeed/Details/";
|
|||||||
import Infrastructure from "@/Pages/Infrastructure/Monitors";
|
import Infrastructure from "@/Pages/Infrastructure/Monitors";
|
||||||
import InfrastructureDetails from "@/Pages/Infrastructure/Details";
|
import InfrastructureDetails from "@/Pages/Infrastructure/Details";
|
||||||
|
|
||||||
|
// Docker
|
||||||
|
import Docker from "@/Pages/Docker/Monitors";
|
||||||
|
import DockerHostDetails from "@/Pages/Docker/HostDetails";
|
||||||
|
import DockerDetails from "@/Pages/Docker/Details";
|
||||||
|
|
||||||
// Checks
|
// Checks
|
||||||
import Checks from "@/Pages/Checks";
|
import Checks from "@/Pages/Checks";
|
||||||
|
|
||||||
@@ -139,6 +144,26 @@ const Routes = () => {
|
|||||||
path="infrastructure/:monitorId"
|
path="infrastructure/:monitorId"
|
||||||
element={<InfrastructureDetails />}
|
element={<InfrastructureDetails />}
|
||||||
/>
|
/>
|
||||||
|
<Route
|
||||||
|
path="docker"
|
||||||
|
element={<Docker />}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path="docker/create"
|
||||||
|
element={<CreateMonitor />}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path="/docker/configure/:monitorId"
|
||||||
|
element={<CreateMonitor />}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path="docker/:monitorId"
|
||||||
|
element={<DockerDetails />}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path="docker/host/:monitorId"
|
||||||
|
element={<DockerHostDetails />}
|
||||||
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="checks/:monitorId?"
|
path="checks/:monitorId?"
|
||||||
element={<Checks />}
|
element={<Checks />}
|
||||||
|
|||||||
@@ -119,6 +119,46 @@ export interface CheckTimings {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mirrors DockerContainerSummary in server/src/types/network.ts.
|
||||||
|
export interface DockerContainerSummary {
|
||||||
|
total: number;
|
||||||
|
running: number;
|
||||||
|
stopped: number;
|
||||||
|
unhealthy: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mirrors DockerContainerStates in server/src/types/network.ts.
|
||||||
|
export const DockerContainerStates = [
|
||||||
|
"created",
|
||||||
|
"running",
|
||||||
|
"paused",
|
||||||
|
"restarting",
|
||||||
|
"removing",
|
||||||
|
"exited",
|
||||||
|
"dead",
|
||||||
|
] as const;
|
||||||
|
export type DockerContainerState = (typeof DockerContainerStates)[number];
|
||||||
|
|
||||||
|
// Mirrors DockerHealthStatuses in server/src/types/network.ts.
|
||||||
|
export const DockerHealthStatuses = ["healthy", "unhealthy", "starting", "none"] as const;
|
||||||
|
export type DockerHealthStatus = (typeof DockerHealthStatuses)[number];
|
||||||
|
|
||||||
|
// Mirrors DockerContainerInfo in server/src/types/network.ts.
|
||||||
|
export interface DockerContainerInfo {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
image: string;
|
||||||
|
state: DockerContainerState;
|
||||||
|
status: string;
|
||||||
|
health: DockerHealthStatus;
|
||||||
|
cpuPct?: number; // fraction of one core; exceeds 1 when using multiple cores
|
||||||
|
memoryUsedBytes?: number;
|
||||||
|
memoryLimitBytes?: number;
|
||||||
|
memoryPct?: number; // 0-1 fraction of the memory limit
|
||||||
|
restartCount?: number;
|
||||||
|
startedAt?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Check {
|
export interface Check {
|
||||||
id: string;
|
id: string;
|
||||||
metadata: CheckMetadata;
|
metadata: CheckMetadata;
|
||||||
@@ -133,6 +173,7 @@ export interface Check {
|
|||||||
host?: CheckHostInfo;
|
host?: CheckHostInfo;
|
||||||
errors?: CheckErrorInfo[];
|
errors?: CheckErrorInfo[];
|
||||||
capture?: CheckCaptureInfo;
|
capture?: CheckCaptureInfo;
|
||||||
|
containerSummary?: DockerContainerSummary;
|
||||||
net?: CheckNetworkInterfaceInfo[];
|
net?: CheckNetworkInterfaceInfo[];
|
||||||
accessibility?: number;
|
accessibility?: number;
|
||||||
bestPractices?: number;
|
bestPractices?: number;
|
||||||
@@ -287,6 +328,7 @@ export type CheckSnapshot = Pick<
|
|||||||
memory?: SnapshotMemoryInfo;
|
memory?: SnapshotMemoryInfo;
|
||||||
disk?: SnapshotDiskInfo[];
|
disk?: SnapshotDiskInfo[];
|
||||||
host?: SnapshotHostInfo;
|
host?: SnapshotHostInfo;
|
||||||
|
containerSummary?: DockerContainerSummary;
|
||||||
};
|
};
|
||||||
export interface HasResponseTime {
|
export interface HasResponseTime {
|
||||||
responseTime: number;
|
responseTime: number;
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import type {
|
|||||||
CheckSnapshot,
|
CheckSnapshot,
|
||||||
GroupedUptimeCheck,
|
GroupedUptimeCheck,
|
||||||
DailyCheckBucket,
|
DailyCheckBucket,
|
||||||
|
DockerContainerInfo,
|
||||||
|
DockerContainerSummary,
|
||||||
} from "@/Types/Check";
|
} from "@/Types/Check";
|
||||||
import type { PageSpeedGroupedCheck } from "@/Types/Check";
|
import type { PageSpeedGroupedCheck } from "@/Types/Check";
|
||||||
import type { GeoContinent } from "@/Types/GeoCheck";
|
import type { GeoContinent } from "@/Types/GeoCheck";
|
||||||
@@ -30,7 +32,6 @@ export type MonitorType = (typeof MonitorTypes)[number];
|
|||||||
export const SelectableMonitorTypes = [
|
export const SelectableMonitorTypes = [
|
||||||
"http",
|
"http",
|
||||||
"ping",
|
"ping",
|
||||||
"docker",
|
|
||||||
"port",
|
"port",
|
||||||
"game",
|
"game",
|
||||||
"grpc",
|
"grpc",
|
||||||
@@ -269,6 +270,41 @@ export interface HardwareDetailsResponse {
|
|||||||
monitorStats: MonitorStats | null;
|
monitorStats: MonitorStats | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mirrors DockerStatsBucket in server/src/domain/checks/check.type.ts.
|
||||||
|
export interface DockerStatsBucket {
|
||||||
|
_id: string;
|
||||||
|
avgResponseTime: number | null;
|
||||||
|
upCount: number;
|
||||||
|
totalCount: number;
|
||||||
|
avgRunning: number | null;
|
||||||
|
avgTotal: number | null;
|
||||||
|
avgUnhealthy: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mirrors DockerStats in server/src/domain/checks/check.type.ts.
|
||||||
|
export interface DockerStats {
|
||||||
|
aggregateData: {
|
||||||
|
totalChecks: number;
|
||||||
|
};
|
||||||
|
upChecks: {
|
||||||
|
totalChecks: number;
|
||||||
|
};
|
||||||
|
aggregate: DockerStatsBucket[];
|
||||||
|
latest: {
|
||||||
|
containers: DockerContainerInfo[];
|
||||||
|
summary?: DockerContainerSummary;
|
||||||
|
checkedAt: string;
|
||||||
|
} | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Response of GET /monitors/docker/details/{monitorId}; mirrors
|
||||||
|
// dockerDetailsResponseSchema in server/src/api/validation/monitorValidation.ts.
|
||||||
|
export interface DockerDetailsResponse {
|
||||||
|
monitor: Monitor;
|
||||||
|
stats: DockerStats;
|
||||||
|
monitorStats: MonitorStats | null;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Game {
|
export interface Game {
|
||||||
name: string;
|
name: string;
|
||||||
options?: {
|
options?: {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { MonitorStatus, MonitorType } from "@/Types/Monitor";
|
import type { MonitorStatus, MonitorType } from "@/Types/Monitor";
|
||||||
import type { PaletteKey } from "@/Utils/Theme/Theme";
|
import type { PaletteKey } from "@/Utils/Theme/Theme";
|
||||||
import type { ValueType } from "@/Components/design-elements/StatusLabel";
|
import type { ValueType } from "@/Components/design-elements/StatusLabel";
|
||||||
|
import type { DockerContainerState } from "@/Types/Check";
|
||||||
|
|
||||||
export const getMonitorPath = (type: MonitorType): string => {
|
export const getMonitorPath = (type: MonitorType): string => {
|
||||||
const pathMap: Record<MonitorType, string> = {
|
const pathMap: Record<MonitorType, string> = {
|
||||||
@@ -12,7 +13,7 @@ export const getMonitorPath = (type: MonitorType): string => {
|
|||||||
websocket: "uptime",
|
websocket: "uptime",
|
||||||
dns: "uptime",
|
dns: "uptime",
|
||||||
unknown: "uptime",
|
unknown: "uptime",
|
||||||
docker: "uptime",
|
docker: "docker",
|
||||||
hardware: "infrastructure",
|
hardware: "infrastructure",
|
||||||
pagespeed: "pagespeed",
|
pagespeed: "pagespeed",
|
||||||
};
|
};
|
||||||
@@ -41,6 +42,19 @@ export const getValuePalette = (value: ValueType): PaletteKey => {
|
|||||||
return paletteMap[value];
|
return paletteMap[value];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getDockerStatePalette = (state: DockerContainerState): PaletteKey => {
|
||||||
|
const paletteMap: Record<DockerContainerState, PaletteKey> = {
|
||||||
|
paused: "warning",
|
||||||
|
created: "warning",
|
||||||
|
running: "success",
|
||||||
|
restarting: "warning",
|
||||||
|
removing: "warning",
|
||||||
|
exited: "error",
|
||||||
|
dead: "error",
|
||||||
|
};
|
||||||
|
return paletteMap[state];
|
||||||
|
};
|
||||||
|
|
||||||
export const getStatusColor = (status: MonitorStatus, theme: any): string => {
|
export const getStatusColor = (status: MonitorStatus, theme: any): string => {
|
||||||
if (status === "up") {
|
if (status === "up") {
|
||||||
return theme.palette.success.light;
|
return theme.palette.success.light;
|
||||||
|
|||||||
@@ -203,6 +203,7 @@
|
|||||||
"uptime": "Uptime",
|
"uptime": "Uptime",
|
||||||
"pagespeed": "Pagespeed",
|
"pagespeed": "Pagespeed",
|
||||||
"infrastructure": "Infrastructure",
|
"infrastructure": "Infrastructure",
|
||||||
|
"docker": "Docker",
|
||||||
"notifications": "Notifications",
|
"notifications": "Notifications",
|
||||||
"tags": "Tags",
|
"tags": "Tags",
|
||||||
"proxies": "Proxies",
|
"proxies": "Proxies",
|
||||||
@@ -924,6 +925,41 @@
|
|||||||
"description": "When monitors go down or recover, incidents appear here with timing, monitor details and resolution history."
|
"description": "When monitors go down or recover, incidents appear here with timing, monitor details and resolution history."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"docker": {
|
||||||
|
"header": {
|
||||||
|
"title": "Docker monitors",
|
||||||
|
"description": "Monitor your Docker hosts and every container running on them."
|
||||||
|
},
|
||||||
|
"fallback": {
|
||||||
|
"title": "No Docker monitors yet",
|
||||||
|
"description": "Add a Docker host to monitor its containers.",
|
||||||
|
"actionButton": "Create a monitor"
|
||||||
|
},
|
||||||
|
"table": {
|
||||||
|
"headers": {
|
||||||
|
"host": "Host",
|
||||||
|
"containers": "Containers"
|
||||||
|
},
|
||||||
|
"containersRunning": "{{running}} of {{total}} running"
|
||||||
|
},
|
||||||
|
"host": {
|
||||||
|
"statBoxes": {
|
||||||
|
"containers": "Containers",
|
||||||
|
"running": "Running",
|
||||||
|
"stopped": "Stopped",
|
||||||
|
"unhealthy": "Unhealthy"
|
||||||
|
},
|
||||||
|
"table": {
|
||||||
|
"headers": {
|
||||||
|
"container": "Containers",
|
||||||
|
"health": "Health",
|
||||||
|
"cpu": "CPU",
|
||||||
|
"memory": "Memory",
|
||||||
|
"restarts": "Restarts"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"infrastructure": {
|
"infrastructure": {
|
||||||
"charts": {
|
"charts": {
|
||||||
"labels": {
|
"labels": {
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ export class DockerProvider implements IStatusProvider<DockerStatusPayload> {
|
|||||||
const systemDelta = stats.cpu_stats.system_cpu_usage - (stats.precpu_stats.system_cpu_usage ?? 0);
|
const systemDelta = stats.cpu_stats.system_cpu_usage - (stats.precpu_stats.system_cpu_usage ?? 0);
|
||||||
const onlineCpus = stats.cpu_stats.online_cpus ?? stats.cpu_stats.cpu_usage.percpu_usage?.length ?? 1;
|
const onlineCpus = stats.cpu_stats.online_cpus ?? stats.cpu_stats.cpu_usage.percpu_usage?.length ?? 1;
|
||||||
if (!(systemDelta > 0) || cpuDelta < 0) return 0;
|
if (!(systemDelta > 0) || cpuDelta < 0) return 0;
|
||||||
return (cpuDelta / systemDelta) * onlineCpus * 100;
|
return (cpuDelta / systemDelta) * onlineCpus;
|
||||||
}
|
}
|
||||||
|
|
||||||
private computeMemory(stats: Dockerode.ContainerStats): Pick<DockerContainerInfo, "memoryUsedBytes" | "memoryLimitBytes" | "memoryPct"> {
|
private computeMemory(stats: Dockerode.ContainerStats): Pick<DockerContainerInfo, "memoryUsedBytes" | "memoryLimitBytes" | "memoryPct"> {
|
||||||
@@ -111,7 +111,7 @@ export class DockerProvider implements IStatusProvider<DockerStatusPayload> {
|
|||||||
return {
|
return {
|
||||||
memoryUsedBytes,
|
memoryUsedBytes,
|
||||||
memoryLimitBytes,
|
memoryLimitBytes,
|
||||||
memoryPct: memoryLimitBytes > 0 ? (memoryUsedBytes / memoryLimitBytes) * 100 : 0,
|
memoryPct: memoryLimitBytes > 0 ? memoryUsedBytes / memoryLimitBytes : 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -117,10 +117,10 @@ export interface DockerContainerInfo {
|
|||||||
state: DockerContainerState;
|
state: DockerContainerState;
|
||||||
status: string;
|
status: string;
|
||||||
health: DockerHealthStatus;
|
health: DockerHealthStatus;
|
||||||
cpuPct?: number;
|
cpuPct?: number; // fraction of one core (docker stats convention / 100); exceeds 1 when using multiple cores
|
||||||
memoryUsedBytes?: number;
|
memoryUsedBytes?: number;
|
||||||
memoryLimitBytes?: number;
|
memoryLimitBytes?: number;
|
||||||
memoryPct?: number;
|
memoryPct?: number; // 0-1 fraction of the memory limit
|
||||||
restartCount?: number;
|
restartCount?: number;
|
||||||
startedAt?: string; // ISO date
|
startedAt?: string; // ISO date
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -324,10 +324,10 @@ describe("DockerProvider", () => {
|
|||||||
const result = await provider.handle(makeMonitor());
|
const result = await provider.handle(makeMonitor());
|
||||||
const container = result.payload?.containers[0];
|
const container = result.payload?.containers[0];
|
||||||
|
|
||||||
expect(container?.cpuPct).toBeCloseTo(80);
|
expect(container?.cpuPct).toBeCloseTo(0.8);
|
||||||
expect(container?.memoryUsedBytes).toBe(200 * 1024 * 1024);
|
expect(container?.memoryUsedBytes).toBe(200 * 1024 * 1024);
|
||||||
expect(container?.memoryLimitBytes).toBe(1024 * 1024 * 1024);
|
expect(container?.memoryLimitBytes).toBe(1024 * 1024 * 1024);
|
||||||
expect(container?.memoryPct).toBeCloseTo(19.53125);
|
expect(container?.memoryPct).toBeCloseTo(0.1953125);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("falls back to the cgroup v1 cache field for page cache", async () => {
|
it("falls back to the cgroup v1 cache field for page cache", async () => {
|
||||||
@@ -351,7 +351,7 @@ describe("DockerProvider", () => {
|
|||||||
|
|
||||||
const result = await provider.handle(makeMonitor());
|
const result = await provider.handle(makeMonitor());
|
||||||
|
|
||||||
expect(result.payload?.containers[0]?.cpuPct).toBeCloseTo(40);
|
expect(result.payload?.containers[0]?.cpuPct).toBeCloseTo(0.4);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns 0 cpu when the system delta is not positive", async () => {
|
it("returns 0 cpu when the system delta is not positive", async () => {
|
||||||
|
|||||||
Reference in new issue
Block a user