diff --git a/client/src/components/monitors/BarDockerCount.tsx b/client/src/components/monitors/BarDockerCount.tsx new file mode 100644 index 000000000..b967661e0 --- /dev/null +++ b/client/src/components/monitors/BarDockerCount.tsx @@ -0,0 +1,95 @@ +import Stack from "@mui/material/Stack"; +import Typography from "@mui/material/Typography"; +import { BaseChart } from "@/components/monitors/Chart"; +import { + ResponsiveContainer, + BarChart, + Bar, + XAxis, + YAxis, + CartesianGrid, + Tooltip, +} from "recharts"; +import { XTick } from "@/components/monitors/ChartResponseTime"; +import { useTheme } from "@mui/material/styles"; +import { BaseBox } from "@/components/design-elements"; +import { useAppSelector } from "@/hooks/AppHooks"; +import { formatDateWithTz, tooltipDateFormatLookup } from "@/utils/TimeUtils"; + +type Datum = Record & { _id: string | number }; + +export const BarDockerCount = ({ + data, + dataKey, + range, + title, + emptyText, +}: { + data: Datum[]; + dataKey: string; + range: string; + title: string; + emptyText?: string; +}) => { + const theme = useTheme(); + const hasData = Array.isArray(data) && data.length > 0; + const uiTimezone = useAppSelector((state: any) => state.ui.timezone); + + const CountTooltip = ({ active, payload, label }: any) => { + if (!active || !payload || !label) return null; + console.log(JSON.stringify(payload, null, 2)); + const fmt = tooltipDateFormatLookup(range); + const value = payload?.[0]?.payload?.[dataKey] ?? 0; + return ( + + + {formatDateWithTz(String(label), fmt, uiTimezone)} + + Containers: {value} + + ); + }; + + return ( + + {!hasData ? ( + + {emptyText || "No data"} + + ) : ( + + + + + + + + + + } + /> + + } cursor={false} /> + + + + )} + + ); +}; + +export default BarDockerCount; diff --git a/client/src/components/monitors/index.tsx b/client/src/components/monitors/index.tsx index 6b4f37ce9..ba36abfbc 100644 --- a/client/src/components/monitors/index.tsx +++ b/client/src/components/monitors/index.tsx @@ -8,3 +8,4 @@ export { HistogramInfrastructure } from "./HistogramInfrastructure"; export { CardDockerContainer } from "./CardDockerContainer"; export { HeaderFilter } from "./HeaderFilter"; export { HistogramDockerPercentage } from "./HistogramDockerPercentage"; +export { BarDockerCount } from "./BarDockerCount"; diff --git a/client/src/locales/en.json b/client/src/locales/en.json index 6c9879ca4..f3591ad72 100644 --- a/client/src/locales/en.json +++ b/client/src/locales/en.json @@ -109,47 +109,46 @@ } }, "checks": { + "details": { + "common": { + "requestTime": "Total request time: {{time}}" + }, + "detailsCard": { + "fields": { + "checkTime": "Check time", + "code": "HTTP Code", + "dns": "DNS", + "download": "Download", + "firstByte": "First byte", + "message": "Message", + "request": "Request", + "status": "Status", + "tcp": "TCP", + "timingPhases": "Timing phases", + "tls": "TLS", + "total": "Total", + "type": "Type", + "wait": "Wait" + }, + "headers": { + "basicInfo": "Basic check info", + "timing": "Timing phases" + }, + "linkText": "View monitor", + "title": "Check details" + }, + "timingChart": { + "title": "Request timings" + } + }, "table": { "empty": "No checks", "headers": { "dateTime": "Date & Time", "statusCode": "Status code" } - }, - "details": { - "common": { - "requestTime": "Total request time: {{time}}" - }, - "detailsCard": { - "title": "Check details", - "linkText": "View monitor", - "headers": { - "basicInfo": "Basic check info", - "timing": "Timing phases" - }, - "fields": { - "status": "Status", - "code": "HTTP Code", - "type": "Type", - "checkTime": "Check time", - "message": "Message", - "timingPhases": "Timing phases", - "wait": "Wait", - "dns": "DNS", - "tcp": "TCP", - "tls": "TLS", - "request": "Request", - "firstByte": "First byte", - "download": "Download", - "total": "Total" - } - }, - "timingChart": { - "title": "Request timings" - } } }, - "common": { "appName": "Checkmate", "breadcrumbs": { @@ -158,6 +157,7 @@ "configure": "Configure", "create": "Create", "diagnostics": "Diagnostics", + "docker": "Docker Monitors", "incidents": "Incidents", "infrastructure": "Infrastructure Monitors", "invite": "Invite", @@ -181,11 +181,11 @@ "disable": "Disable", "enable": "Enable", "exportJson": "Export to JSON", + "home": "Return home", "importJson": "Import from JSON", "incidents": "Incidents", "limitReached": "Your plan's limit has been reached", "no": "No", - "home": "Return home", "pause": "Pause", "range": { "all": "All", @@ -240,12 +240,12 @@ "weight": "Weight" }, "uptime": { + "avgResponseTime": "Avg response time", "detail": "Total checks", "downTitle": "Downtime", "emptyDown": "Great, no downtime!", "emptyUp": "No checks yet", - "upTitle": "Uptime", - "avgResponseTime": "Avg response time" + "upTitle": "Uptime" } }, "dialog": { @@ -259,11 +259,11 @@ "headers": { "actions": "Actions", "active": "Active", + "message": "Message", "monitor": "Monitor", "name": "Name", "status": "Status", - "type": "Type", - "message": "Message" + "type": "Type" } }, "toasts": { @@ -280,30 +280,20 @@ }, "diagnostics": { "infoBox": { - "title": "System Diagnostics", - "description": "Review system logs and background job status to troubleshoot issues. Monitor the health of your monitoring infrastructure and investigate any problems." - }, - "tabs": { - "logs": "Logs", - "queue": "Queue", - "config": "Config", - "access": "Access" + "description": "Review system logs and background job status to troubleshoot issues. Monitor the health of your monitoring infrastructure and investigate any problems.", + "title": "System Diagnostics" }, "logs": { "table": { "headers": { - "timestamp": "Timestamp", "level": "Level", - "service": "Service" + "service": "Service", + "timestamp": "Timestamp" } } }, "queue": { "stats": { - "monitoringJobs": { - "title": "Monitoring jobs", - "tooltip": "Total number of monitoring jobs in the queue" - }, "activeJobs": { "title": "Active jobs", "tooltip": "Number of jobs being processed" @@ -312,27 +302,37 @@ "title": "Failing jobs", "tooltip": "Jobs that failed on their last execution" }, - "totalRuns": { - "title": "Total runs", - "tooltip": "Total number of job executions" + "monitoringJobs": { + "title": "Monitoring jobs", + "tooltip": "Total number of monitoring jobs in the queue" }, "totalFailures": { "title": "Total failures", "tooltip": "Total number of failed job executions" + }, + "totalRuns": { + "title": "Total runs", + "tooltip": "Total number of job executions" } }, "table": { "headers": { - "jobId": "Job ID", - "url": "URL", - "interval": "Interval", - "runs": "Runs", - "lastRun": "Last run", - "lockedAt": "Locked at", "finishedAt": "Finished at", - "lastRunTook": "Last run took (ms)" + "interval": "Interval", + "jobId": "Job ID", + "lastRun": "Last run", + "lastRunTook": "Last run took (ms)", + "lockedAt": "Locked at", + "runs": "Runs", + "url": "URL" } } + }, + "tabs": { + "access": "Access", + "config": "Config", + "logs": "Logs", + "queue": "Queue" } }, "export": { @@ -517,6 +517,38 @@ } }, "docker": { + "details": { + "dockerContainerCard": { + "fields": { + "health": "Health", + "id": "ID", + "image": "Image", + "ports": "Ports", + "status": "Status" + }, + "title": "Container: {{name}}", + "values": { + "healthy": "Healthy", + "unhealthy": "Unhealthy" + } + }, + "healthyChart": { + "empty": "No data", + "title": "Healthy container %" + }, + "healthyCountChart": { + "empty": "No data", + "title": "# of healthy containers" + }, + "runningChart": { + "empty": "No data", + "title": "Running container %" + }, + "runningCountChart": { + "empty": "No data", + "title": "# of running containers" + } + }, "fallback": { "actionButton": "Create a monitor!", "checks": [ @@ -531,30 +563,6 @@ "headers": { "runningContainers": "Running containers" } - }, - "details": { - "dockerContainerCard": { - "title": "Container: {{name}}", - "fields": { - "status": "Status", - "health": "Health", - "id": "ID", - "image": "Image", - "ports": "Ports" - }, - "values": { - "healthy": "Healthy", - "unhealthy": "Unhealthy" - } - }, - "healthyChart": { - "title": "Healthy container %", - "empty": "No data" - }, - "runningChart": { - "title": "Running container %", - "empty": "No data" - } } }, "infrastructure": { diff --git a/client/src/pages/docker/DockerDetails.tsx b/client/src/pages/docker/DockerDetails.tsx index c3f3bce27..b2f23d5de 100644 --- a/client/src/pages/docker/DockerDetails.tsx +++ b/client/src/pages/docker/DockerDetails.tsx @@ -2,6 +2,7 @@ import { BasePage, StatBox } from "@/components/design-elements"; import { HeaderControls, HeaderRange, + BarDockerCount, HistogramDockerPercentage, } from "@/components/monitors"; import Stack from "@mui/material/Stack"; @@ -38,7 +39,7 @@ const DockerDetailsPage = () => { const monitor = response?.data?.monitor; const stats = response?.data?.stats; const checks = (response?.data?.checks || []) as any; - const snapshot = monitor?.latestChecks?.[0].containerSnapshot || []; + const snapshot = monitor?.latestChecks?.[0].dockerContainers || []; const palette = getStatusPalette(monitor?.status || "initializing"); const streakDuration = stats?.currentStreakStartedAt @@ -85,6 +86,20 @@ const DockerDetailsPage = () => { ))} + + { data={checks} dataKey="runningPercent" range={range} - title={t("monitors.docker.details.runningChart.title")} - emptyText={t("monitors.docker.details.runningChart.empty")} + title={t("monitors.docker.details.healthyChart.title")} + emptyText={t("monitors.docker.details.healthyChart.empty")} /> ); diff --git a/client/src/pages/docker/DockerMonitorsTable.tsx b/client/src/pages/docker/DockerMonitorsTable.tsx index 3489cfb2f..c794099dc 100644 --- a/client/src/pages/docker/DockerMonitorsTable.tsx +++ b/client/src/pages/docker/DockerMonitorsTable.tsx @@ -116,8 +116,10 @@ export const DockerMonitorsTable = ({ ), render: (row) => { - const containerCount = (row.latestChecks?.[0]?.dockerContainers || []) - .length; + console.log(row); + const containerCount = ( + row.latestChecks?.[0]?.dockerContainers || [] + ).filter((c: any) => c?.running).length; return containerCount; }, }, diff --git a/client/src/types/check.ts b/client/src/types/check.ts index c61d8d72c..b6d1e4b4f 100644 --- a/client/src/types/check.ts +++ b/client/src/types/check.ts @@ -123,7 +123,7 @@ export interface ICheck { lighthouse?: ICheckLighthouseFields; system?: ISystemInfo; // Present for docker monitor checks - containerSnapshot?: IDockerContainerSummary[]; + dockerContainers?: IDockerContainerSummary[]; } export interface CheckWithMonitor { _id: string;