update check and monitor domains
This commit is contained in:
1 parent
9c8bf4bb05
commit
686ded2137
7 files changed
+87
-2
No files matched your search
@@ -112,6 +112,7 @@ export const checkSnapshotResponseSchema = z
|
||||
bestPractices: z.number().optional(),
|
||||
seo: z.number().optional(),
|
||||
performance: z.number().optional(),
|
||||
containerSummary: z.object({ total: z.number(), running: z.number(), stopped: z.number(), unhealthy: z.number() }).optional(),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import type {
|
||||
GotTimings,
|
||||
ILighthouseAudit,
|
||||
} from "@/domain/checks/check.type.js";
|
||||
import { DockerContainerInfo, DockerContainerStates, DockerContainerSummary, DockerHealthStatuses } from "@/types/network.js";
|
||||
|
||||
type CheckMetadataDocument = Omit<CheckMetadata, "monitorId" | "teamId"> & {
|
||||
monitorId: Types.ObjectId;
|
||||
@@ -172,6 +173,34 @@ const auditsSchema = new Schema<CheckAudits>(
|
||||
{ _id: false }
|
||||
);
|
||||
|
||||
const dockerContainerSchema = new Schema<DockerContainerInfo>(
|
||||
{
|
||||
id: { type: String, required: true },
|
||||
name: { type: String, default: "" },
|
||||
image: { type: String, default: "" },
|
||||
state: { type: String, enum: DockerContainerStates, default: "created" },
|
||||
status: { type: String, default: "" },
|
||||
health: { type: String, enum: DockerHealthStatuses, default: "none" },
|
||||
cpuPct: { type: Number },
|
||||
memoryUsedBytes: { type: Number },
|
||||
memoryLimitBytes: { type: Number },
|
||||
memoryPct: { type: Number },
|
||||
restartCount: { type: Number },
|
||||
startedAt: { type: String },
|
||||
},
|
||||
{ _id: false }
|
||||
);
|
||||
|
||||
const containerSummarySchema = new Schema<DockerContainerSummary>(
|
||||
{
|
||||
total: { type: Number, default: 0 },
|
||||
running: { type: Number, default: 0 },
|
||||
stopped: { type: Number, default: 0 },
|
||||
unhealthy: { type: Number, default: 0 },
|
||||
},
|
||||
{ _id: false }
|
||||
);
|
||||
|
||||
const metadataSchema = new Schema<CheckMetadataDocument>(
|
||||
{
|
||||
monitorId: {
|
||||
@@ -268,6 +297,14 @@ const CheckSchema = new Schema<CheckDocument>(
|
||||
type: auditsSchema,
|
||||
default: undefined,
|
||||
},
|
||||
containers: {
|
||||
type: [dockerContainerSchema],
|
||||
default: undefined,
|
||||
},
|
||||
containerSummary: {
|
||||
type: containerSummarySchema,
|
||||
default: undefined,
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
@@ -291,5 +328,5 @@ CheckSchema.index({ "metadata.teamId": 1, status: 1, createdAt: -1 });
|
||||
const CheckModel = model<CheckDocument>("Check", CheckSchema);
|
||||
|
||||
export type { CheckDocument, CheckMetadataDocument };
|
||||
export { CheckModel };
|
||||
export { CheckModel, containerSummarySchema };
|
||||
export default CheckModel;
|
||||
@@ -167,6 +167,8 @@ class MongoChecksRepository implements IChecksRepository {
|
||||
seo: doc.seo,
|
||||
performance: doc.performance,
|
||||
audits: mapAudits(doc.audits),
|
||||
containers: doc.containers,
|
||||
containerSummary: doc.containerSummary,
|
||||
createdAt: toDateString(doc.createdAt),
|
||||
updatedAt: toDateString(doc.updatedAt),
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Types } from "mongoose";
|
||||
import { IChecksRepository } from "@/domain/checks/check.repository.interface.js";
|
||||
import { IMonitorsRepository } from "@/domain/monitors/monitor.repository.interface.js";
|
||||
import type { Check, CheckErrorInfo, ChecksQueryResult, ChecksSummary, ILighthouseAudit } from "@/domain/checks/check.type.js";
|
||||
import type { MonitorPayloadMap, MonitorStatusResponse } from "@/types/network.js";
|
||||
import type { DockerStatusPayload, MonitorPayloadMap, MonitorStatusResponse } from "@/types/network.js";
|
||||
import type { HardwareStatusPayload, PageSpeedStatusPayload } from "@/types/network.js";
|
||||
import { AppError } from "@/utils/AppError.js";
|
||||
import { ILogger } from "@/utils/logger.js";
|
||||
@@ -131,6 +131,12 @@ export class CheckService implements ICheckService {
|
||||
check.capture = hardwarePayload?.capture;
|
||||
check.net = net;
|
||||
}
|
||||
|
||||
if (type === "docker") {
|
||||
const dockerPayload = payload as DockerStatusPayload | undefined;
|
||||
check.containers = dockerPayload?.containers;
|
||||
check.containerSummary = dockerPayload?.summary;
|
||||
}
|
||||
return check;
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import type {
|
||||
SnapshotHostInfo,
|
||||
SnapshotMemoryInfo,
|
||||
} from "@/domain/checks/check.type.js";
|
||||
import { DockerContainerSummary } from "@/types/network.js";
|
||||
import { toDateString } from "@/utils/mongoMappers.js";
|
||||
|
||||
export type CheckSnapshotSource = Pick<
|
||||
@@ -23,6 +24,7 @@ export type CheckSnapshotSource = Pick<
|
||||
disk?: CheckDiskInfo[];
|
||||
host?: CheckHostInfo;
|
||||
audits?: CheckAudits;
|
||||
containerSummary?: DockerContainerSummary;
|
||||
};
|
||||
|
||||
const mapCpu = (cpu?: CheckCpuInfo): SnapshotCpuInfo | undefined =>
|
||||
@@ -66,6 +68,9 @@ const mapAudits = (audits?: CheckAudits): CheckAudits | undefined =>
|
||||
tbt: audits.tbt,
|
||||
};
|
||||
|
||||
const mapContainerSummary = (summary?: DockerContainerSummary): DockerContainerSummary | undefined =>
|
||||
summary && { total: summary.total, running: summary.running, stopped: summary.stopped, unhealthy: summary.unhealthy };
|
||||
|
||||
export const toCheckSnapshot = (source: CheckSnapshotSource): CheckSnapshot => ({
|
||||
id: source.id,
|
||||
status: source.status,
|
||||
@@ -82,4 +87,5 @@ export const toCheckSnapshot = (source: CheckSnapshotSource): CheckSnapshot => (
|
||||
seo: source.seo,
|
||||
performance: source.performance,
|
||||
audits: mapAudits(source.audits),
|
||||
containerSummary: mapContainerSummary(source.containerSummary),
|
||||
});
|
||||
@@ -1,5 +1,7 @@
|
||||
import type { MonitorType } from "@/domain/monitors/monitor.type.js";
|
||||
import { DockerContainerInfo, DockerContainerSummary } from "@/types/network.js";
|
||||
import type { Response } from "got";
|
||||
import { number } from "zod";
|
||||
|
||||
export const CHECK_TTL_SENTINEL = 366;
|
||||
|
||||
@@ -107,6 +109,8 @@ export interface Check {
|
||||
host?: CheckHostInfo;
|
||||
errors?: CheckErrorInfo[];
|
||||
capture?: CheckCaptureInfo;
|
||||
containers?: DockerContainerInfo[];
|
||||
containerSummary?: DockerContainerSummary;
|
||||
net?: CheckNetworkInterfaceInfo[];
|
||||
accessibility?: number;
|
||||
bestPractices?: number;
|
||||
@@ -197,6 +201,8 @@ export type CheckSnapshot = Pick<
|
||||
memory?: SnapshotMemoryInfo;
|
||||
disk?: SnapshotDiskInfo[];
|
||||
host?: SnapshotHostInfo;
|
||||
// Docker Only
|
||||
containerSummary?: DockerContainerSummary;
|
||||
};
|
||||
export interface HardwareDiskStats {
|
||||
name: string;
|
||||
@@ -252,3 +258,28 @@ export type DailyCheckBucket = {
|
||||
downChecks: number;
|
||||
avgResponseTime: number | null;
|
||||
};
|
||||
|
||||
export type DockerStatsBucket = {
|
||||
_id: string;
|
||||
avgResponseTime: number | null;
|
||||
upCount: number;
|
||||
totalCount: number;
|
||||
avgRunning: number | null;
|
||||
avgTotal: number | null;
|
||||
avgUnhealthy: number | null;
|
||||
};
|
||||
|
||||
export interface DockerStats {
|
||||
aggregateData: { totalChecks: number };
|
||||
upChecks: { totalChecks: number };
|
||||
aggregate: DockerStatsBucket[];
|
||||
latest: {
|
||||
containers: DockerContainerInfo[];
|
||||
summary?: DockerContainerSummary;
|
||||
checkedAt: string;
|
||||
} | null;
|
||||
}
|
||||
|
||||
export interface DockerChecksResult extends DockerStats {
|
||||
monitorType: "docker";
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import type {
|
||||
SnapshotHostInfo,
|
||||
SnapshotMemoryInfo,
|
||||
} from "@/domain/checks/check.type.js";
|
||||
import { containerSummarySchema } from "@/domain/checks/check.model.js";
|
||||
|
||||
type CheckSnapshotDocument = Omit<CheckSnapshot, "createdAt"> & { createdAt: Date };
|
||||
|
||||
@@ -113,6 +114,7 @@ const checkSnapshotSchema = new Schema<CheckSnapshotDocument>(
|
||||
seo: { type: Number },
|
||||
performance: { type: Number },
|
||||
audits: { type: snapshotAuditsSchema },
|
||||
containerSummary: { type: containerSummarySchema },
|
||||
createdAt: { type: Date, required: true },
|
||||
},
|
||||
{ _id: false, suppressReservedKeysWarning: true }
|
||||
|
||||
Reference in new issue
Block a user