stauts
This commit is contained in:
1 parent
f56f91c31d
commit
7a01a8a8a3
7 files changed
+56
-36
No files matched your search
@@ -11,7 +11,6 @@ export const useInitForm = ({
|
||||
}) => {
|
||||
return useMemo(() => {
|
||||
const apiToForm = (apiData: IMonitor): FormValues => {
|
||||
console.log(JSON.stringify(apiData));
|
||||
return {
|
||||
type: apiData.type,
|
||||
url: apiData.url,
|
||||
|
||||
@@ -38,9 +38,7 @@ const DockerDetailsPage = () => {
|
||||
const monitor = response?.data?.monitor;
|
||||
const stats = response?.data?.stats;
|
||||
const checks = (response?.data?.checks || []) as any;
|
||||
const latestCheck = checks[0];
|
||||
const snapshot = latestCheck?.runningContainersSnapshot || [];
|
||||
console.log(checks);
|
||||
const snapshot = monitor?.latestChecks?.[0].containerSnapshot || [];
|
||||
const palette = getStatusPalette(monitor?.status || "initializing");
|
||||
|
||||
const streakDuration = stats?.currentStreakStartedAt
|
||||
|
||||
@@ -31,7 +31,6 @@ export const DockerMonitorsTable = ({
|
||||
const navigate = useNavigate();
|
||||
const theme = useTheme();
|
||||
const { patch } = usePatch<any, IMonitor>();
|
||||
console.log(monitors);
|
||||
const handlePageChange = (
|
||||
_e: React.MouseEvent<HTMLButtonElement> | null,
|
||||
newPage: number
|
||||
@@ -124,7 +123,11 @@ export const DockerMonitorsTable = ({
|
||||
},
|
||||
{
|
||||
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)} />,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -123,7 +123,7 @@ export interface ICheck {
|
||||
lighthouse?: ICheckLighthouseFields;
|
||||
system?: ISystemInfo;
|
||||
// Present for docker monitor checks
|
||||
dockerContainers?: IDockerContainerSummary[];
|
||||
containerSnapshot?: IDockerContainerSummary[];
|
||||
}
|
||||
export interface CheckWithMonitor {
|
||||
_id: string;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import mongoose, { Schema, Document, Types } from "mongoose";
|
||||
import type { IDockerContainerSummary } from "@/db/models/checks/Check.js";
|
||||
import {
|
||||
Check,
|
||||
Incident,
|
||||
@@ -33,6 +34,13 @@ export interface IMonitorThresholds {
|
||||
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 {
|
||||
_id: Types.ObjectId;
|
||||
orgId: Types.ObjectId;
|
||||
@@ -48,11 +56,7 @@ export interface IMonitor extends Document {
|
||||
n: number; // Number of consecutive successes required to change status
|
||||
thresholds?: IMonitorThresholds;
|
||||
lastCheckedAt?: Date;
|
||||
latestChecks: {
|
||||
status: MonitorStatus;
|
||||
responseTime: number;
|
||||
checkedAt: Date;
|
||||
}[];
|
||||
latestChecks: LatestCheck[];
|
||||
notificationChannels?: Types.ObjectId[];
|
||||
createdBy: Types.ObjectId;
|
||||
updatedBy: Types.ObjectId;
|
||||
@@ -104,6 +108,32 @@ const MonitorSchema = new Schema<IMonitor>(
|
||||
},
|
||||
responseTime: { type: Number, 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: [],
|
||||
|
||||
@@ -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,
|
||||
} from "@/db/models/index.js";
|
||||
import { StatusResponse } from "./NetworkService.js";
|
||||
import { LatestCheck } from "@/db/models/monitors/Monitor.js";
|
||||
|
||||
const emptyMetrics = (): ThresholdEvaluationResult["metrics"] => ({
|
||||
cpu: { breached: false },
|
||||
@@ -74,11 +75,21 @@ class StatusService implements IStatusService {
|
||||
|
||||
// Store latest checks for display
|
||||
monitor.latestChecks = monitor.latestChecks || [];
|
||||
monitor.latestChecks.push({
|
||||
const nextCheck: LatestCheck = {
|
||||
status: newStatus,
|
||||
responseTime: statusResponse.responseTime,
|
||||
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) {
|
||||
monitor.latestChecks.shift();
|
||||
}
|
||||
@@ -102,6 +113,7 @@ class StatusService implements IStatusService {
|
||||
if (allDifferent && monitor.status !== newStatus) {
|
||||
monitor.status = newStatus;
|
||||
}
|
||||
|
||||
return [await monitor.save(), allDifferent];
|
||||
}
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user