handle docker checks
This commit is contained in:
1 parent
1a1dc7d807
commit
78d3b23e93
3 files changed
+70
-4
No files matched your search
@@ -24,6 +24,7 @@ import { getHardwareUpChecks, getHardwareStats, getHardwareTotalChecks } from "@
|
||||
import { CheckFilter, DateRange } from "@/types/query.js";
|
||||
import { AppError } from "@/utils/AppError.js";
|
||||
import { NETWORK_ERROR } from "@/types/network.js";
|
||||
import { getDockerLatestCheck, getDockerStats, getDockerTotalChecks, getDockerUpChecks } from "@/domain/checks/check.docker.aggregation.js";
|
||||
|
||||
const SERVICE_NAME = "ChecksRepository";
|
||||
|
||||
@@ -304,6 +305,9 @@ class MongoChecksRepository implements IChecksRepository {
|
||||
if (options?.type === "pagespeed") {
|
||||
return this.findPageSpeedDateRangeChecks(monitorObjectId, start, end, dateString);
|
||||
}
|
||||
if (options?.type === "docker") {
|
||||
return this.findDockerDateRangeChecks(monitorObjectId, start, end, dateString);
|
||||
}
|
||||
return this.findUptimeDateRangeChecks(options?.type ?? "http", monitorObjectId, start, end, dateString);
|
||||
};
|
||||
|
||||
@@ -414,7 +418,7 @@ class MongoChecksRepository implements IChecksRepository {
|
||||
return totalDeleted;
|
||||
};
|
||||
private findUptimeDateRangeChecks = async (
|
||||
monitorType: Exclude<MonitorType, "hardware" | "pagespeed">,
|
||||
monitorType: Exclude<MonitorType, "hardware" | "pagespeed" | "docker">,
|
||||
monitorObjectId: mongoose.Types.ObjectId,
|
||||
startDate: Date,
|
||||
endDate: Date,
|
||||
@@ -630,6 +634,30 @@ class MongoChecksRepository implements IChecksRepository {
|
||||
groupedChecks: result?.groupedChecks ?? [],
|
||||
};
|
||||
};
|
||||
|
||||
private findDockerDateRangeChecks = async (monitorObjectId: mongoose.Types.ObjectId, startDate: Date, endDate: Date, dateString: string) => {
|
||||
const monitorId = monitorObjectId.toHexString();
|
||||
const dates = { start: startDate, end: endDate };
|
||||
const [totalChecks, upChecks, aggregate, latestDoc] = await Promise.all([
|
||||
getDockerTotalChecks(monitorId, dates),
|
||||
getDockerUpChecks(monitorId, dates),
|
||||
getDockerStats(monitorId, dates, dateString),
|
||||
getDockerLatestCheck(monitorId),
|
||||
]);
|
||||
return {
|
||||
monitorType: "docker" as const,
|
||||
aggregateData: { totalChecks: totalChecks ?? 0 },
|
||||
upChecks,
|
||||
aggregate,
|
||||
latest: latestDoc
|
||||
? {
|
||||
containers: latestDoc.containers ?? [],
|
||||
summary: latestDoc.containerSummary,
|
||||
checkedAt: toDateString(latestDoc.createdAt),
|
||||
}
|
||||
: null,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export default MongoChecksRepository;
|
||||
@@ -1,7 +1,6 @@
|
||||
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;
|
||||
|
||||
@@ -151,11 +150,10 @@ export interface PageSpeedGroupedCheck {
|
||||
accessibility: number;
|
||||
bestPractices: number;
|
||||
seo: number;
|
||||
totalChecks: number;
|
||||
}
|
||||
|
||||
export interface UptimeChecksResult {
|
||||
monitorType: Exclude<MonitorType, "hardware" | "pagespeed">;
|
||||
monitorType: Exclude<MonitorType, "hardware" | "pagespeed" | "docker">;
|
||||
groupedChecks: GroupedUptimeCheck[];
|
||||
groupedUpChecks: GroupedCheck[];
|
||||
groupedDownChecks: GroupedCheck[];
|
||||
|
||||
Reference in new issue
Block a user