This commit is contained in:
Alex Holliday committed 2025-12-30 20:30:20 +00:00
1 parent f56f91c31d
commit 7a01a8a8a3
7 files changed
+56 -36

No files matched your search

@@ -11,7 +11,6 @@ export const useInitForm = ({
}) => { }) => {
return useMemo(() => { return useMemo(() => {
const apiToForm = (apiData: IMonitor): FormValues => { const apiToForm = (apiData: IMonitor): FormValues => {
console.log(JSON.stringify(apiData));
return { return {
type: apiData.type, type: apiData.type,
url: apiData.url, url: apiData.url,
+1 -3
View File
@@ -38,9 +38,7 @@ const DockerDetailsPage = () => {
const monitor = response?.data?.monitor; const monitor = response?.data?.monitor;
const stats = response?.data?.stats; const stats = response?.data?.stats;
const checks = (response?.data?.checks || []) as any; const checks = (response?.data?.checks || []) as any;
const latestCheck = checks[0]; const snapshot = monitor?.latestChecks?.[0].containerSnapshot || [];
const snapshot = latestCheck?.runningContainersSnapshot || [];
console.log(checks);
const palette = getStatusPalette(monitor?.status || "initializing"); const palette = getStatusPalette(monitor?.status || "initializing");
const streakDuration = stats?.currentStreakStartedAt const streakDuration = stats?.currentStreakStartedAt
@@ -31,7 +31,6 @@ export const DockerMonitorsTable = ({
const navigate = useNavigate(); const navigate = useNavigate();
const theme = useTheme(); const theme = useTheme();
const { patch } = usePatch<any, IMonitor>(); const { patch } = usePatch<any, IMonitor>();
console.log(monitors);
const handlePageChange = ( const handlePageChange = (
_e: React.MouseEvent<HTMLButtonElement> | null, _e: React.MouseEvent<HTMLButtonElement> | null,
newPage: number newPage: number
@@ -124,7 +123,11 @@ export const DockerMonitorsTable = ({
}, },
{ {
id: "actions", id: "actions",
content: <Typography component="div">{t("common.table.headers.actions")}</Typography>, content: (
<Typography component="div">
{t("common.table.headers.actions")}
</Typography>
),
render: (row) => <ActionsMenu items={getActions(row)} />, render: (row) => <ActionsMenu items={getActions(row)} />,
}, },
]; ];
+1 -1
View File
@@ -123,7 +123,7 @@ export interface ICheck {
lighthouse?: ICheckLighthouseFields; lighthouse?: ICheckLighthouseFields;
system?: ISystemInfo; system?: ISystemInfo;
// Present for docker monitor checks // Present for docker monitor checks
dockerContainers?: IDockerContainerSummary[]; containerSnapshot?: IDockerContainerSummary[];
} }
export interface CheckWithMonitor { export interface CheckWithMonitor {
_id: string; _id: string;
+35 -5
View File
@@ -1,4 +1,5 @@
import mongoose, { Schema, Document, Types } from "mongoose"; import mongoose, { Schema, Document, Types } from "mongoose";
import type { IDockerContainerSummary } from "@/db/models/checks/Check.js";
import { import {
Check, Check,
Incident, Incident,
@@ -33,6 +34,13 @@ export interface IMonitorThresholds {
temperature?: number; temperature?: number;
} }
export interface LatestCheck {
status: MonitorStatus;
responseTime: number;
checkedAt: Date;
// Snapshot of containers from the latest docker check (array from payload.data)
containerSnapshot?: IDockerContainerSummary[];
}
export interface IMonitor extends Document { export interface IMonitor extends Document {
_id: Types.ObjectId; _id: Types.ObjectId;
orgId: Types.ObjectId; orgId: Types.ObjectId;
@@ -48,11 +56,7 @@ export interface IMonitor extends Document {
n: number; // Number of consecutive successes required to change status n: number; // Number of consecutive successes required to change status
thresholds?: IMonitorThresholds; thresholds?: IMonitorThresholds;
lastCheckedAt?: Date; lastCheckedAt?: Date;
latestChecks: { latestChecks: LatestCheck[];
status: MonitorStatus;
responseTime: number;
checkedAt: Date;
}[];
notificationChannels?: Types.ObjectId[]; notificationChannels?: Types.ObjectId[];
createdBy: Types.ObjectId; createdBy: Types.ObjectId;
updatedBy: Types.ObjectId; updatedBy: Types.ObjectId;
@@ -104,6 +108,32 @@ const MonitorSchema = new Schema<IMonitor>(
}, },
responseTime: { type: Number, required: true }, responseTime: { type: Number, required: true },
checkedAt: { type: Date, required: true }, checkedAt: { type: Date, required: true },
containerSnapshot: {
type: [
{
container_id: { type: String },
container_name: { type: String },
status: { type: String },
health: {
healthy: { type: Boolean },
source: { type: String },
message: { type: String },
},
running: { type: Boolean },
base_image: { type: String },
exposed_ports: [
{
port: { type: String },
protocol: { type: String },
},
],
started_at: { type: Number },
finished_at: { type: Number },
},
],
required: false,
default: undefined,
},
}, },
], ],
default: [], default: [],
@@ -362,28 +362,6 @@ class MonitorService implements IMonitorService {
}, },
}, },
}, },
runningContainersSnapshot: {
$last: {
$map: {
input: {
$filter: {
input: { $ifNull: ["$dockerContainers", []] },
as: "c",
cond: { $eq: ["$$c.running", true] },
},
},
as: "c",
in: {
container_id: "$$c.container_id",
container_name: "$$c.container_name",
base_image: "$$c.base_image",
exposed_ports: "$$c.exposed_ports",
status: "$$c.status",
health: "$$c.health",
},
},
},
},
}; };
}; };
@@ -5,6 +5,7 @@ import {
ICheck, ICheck,
} from "@/db/models/index.js"; } from "@/db/models/index.js";
import { StatusResponse } from "./NetworkService.js"; import { StatusResponse } from "./NetworkService.js";
import { LatestCheck } from "@/db/models/monitors/Monitor.js";
const emptyMetrics = (): ThresholdEvaluationResult["metrics"] => ({ const emptyMetrics = (): ThresholdEvaluationResult["metrics"] => ({
cpu: { breached: false }, cpu: { breached: false },
@@ -74,11 +75,21 @@ class StatusService implements IStatusService {
// Store latest checks for display // Store latest checks for display
monitor.latestChecks = monitor.latestChecks || []; monitor.latestChecks = monitor.latestChecks || [];
monitor.latestChecks.push({ const nextCheck: LatestCheck = {
status: newStatus, status: newStatus,
responseTime: statusResponse.responseTime, responseTime: statusResponse.responseTime,
checkedAt: monitor.lastCheckedAt, checkedAt: monitor.lastCheckedAt,
}); };
// If this is a docker type, add the snapshot
if (monitor.type === "docker") {
const payload: any = statusResponse.payload;
nextCheck.containerSnapshot = payload.data;
}
monitor.latestChecks.push(nextCheck);
if (monitor.type === "docker") {
}
while (monitor.latestChecks.length > MAX_LATEST_CHECKS) { while (monitor.latestChecks.length > MAX_LATEST_CHECKS) {
monitor.latestChecks.shift(); monitor.latestChecks.shift();
} }
@@ -102,6 +113,7 @@ class StatusService implements IStatusService {
if (allDifferent && monitor.status !== newStatus) { if (allDifferent && monitor.status !== newStatus) {
monitor.status = newStatus; monitor.status = newStatus;
} }
return [await monitor.save(), allDifferent]; return [await monitor.save(), allDifferent];
} }
}; };