recent checks
This commit is contained in:
1 parent
5731283c46
commit
6f9fefddd2
7 files changed
+14
-24
No files matched your search
@@ -324,7 +324,6 @@ class MonitorController {
|
|||||||
try {
|
try {
|
||||||
await getMonitorsByTeamIdParamValidation.validateAsync(req.params);
|
await getMonitorsByTeamIdParamValidation.validateAsync(req.params);
|
||||||
await getMonitorsWithChecksQueryValidation.validateAsync(req.query);
|
await getMonitorsWithChecksQueryValidation.validateAsync(req.query);
|
||||||
|
|
||||||
const explain = optionalBoolean(req?.query?.explain, "explain");
|
const explain = optionalBoolean(req?.query?.explain, "explain");
|
||||||
const limit = optionalNumber(req?.query?.limit, "limit");
|
const limit = optionalNumber(req?.query?.limit, "limit");
|
||||||
const page = optionalNumber(req?.query?.page, "page");
|
const page = optionalNumber(req?.query?.page, "page");
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import { IStatusPageService } from "@/service/business/statusPageService.js";
|
|||||||
import { IMonitorsRepository } from "@/repositories/index.js";
|
import { IMonitorsRepository } from "@/repositories/index.js";
|
||||||
import { ISettingsService } from "@/service/system/settingsService.js";
|
import { ISettingsService } from "@/service/system/settingsService.js";
|
||||||
import { ParseBoolean } from "@/utils/utils.js";
|
import { ParseBoolean } from "@/utils/utils.js";
|
||||||
import { MonitorWithChecks } from "@/types/index.js";
|
|
||||||
import { NormalizeData } from "@/utils/dataUtils.js";
|
import { NormalizeData } from "@/utils/dataUtils.js";
|
||||||
|
|
||||||
const SERVICE_NAME = "statusPageController";
|
const SERVICE_NAME = "statusPageController";
|
||||||
@@ -84,7 +83,7 @@ class StatusPageController {
|
|||||||
|
|
||||||
const monitors = await this.monitorsRepository.findByIdsWithChecks(statusPage.monitors);
|
const monitors = await this.monitorsRepository.findByIdsWithChecks(statusPage.monitors);
|
||||||
const normalizedMonitors = monitors.map((monitor) => {
|
const normalizedMonitors = monitors.map((monitor) => {
|
||||||
const normalizedChecks = NormalizeData(monitor.checks, 10, 100);
|
const normalizedChecks = NormalizeData(monitor.recentChecks, 10, 100);
|
||||||
if (!showURL) {
|
if (!showURL) {
|
||||||
const { url, port, secret, notifications, ...rest } = monitor;
|
const { url, port, secret, notifications, ...rest } = monitor;
|
||||||
return { ...rest, checks: normalizedChecks };
|
return { ...rest, checks: normalizedChecks };
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { type MonitorType, type Monitor, type MonitorsSummary, type MonitorWithChecks } from "@/types/index.js";
|
import { type MonitorType, type Monitor, type MonitorsSummary } from "@/types/index.js";
|
||||||
|
|
||||||
export interface TeamQueryConfig {
|
export interface TeamQueryConfig {
|
||||||
limit?: number;
|
limit?: number;
|
||||||
@@ -25,7 +25,7 @@ export interface IMonitorsRepository {
|
|||||||
findAll(): Promise<Monitor[] | null>;
|
findAll(): Promise<Monitor[] | null>;
|
||||||
findByTeamId(teamId: string, config: TeamQueryConfig): Promise<Monitor[] | null>;
|
findByTeamId(teamId: string, config: TeamQueryConfig): Promise<Monitor[] | null>;
|
||||||
findByIds(monitorIds: string[]): Promise<Monitor[]>;
|
findByIds(monitorIds: string[]): Promise<Monitor[]>;
|
||||||
findByIdsWithChecks(monitorIds: string[], checksCount?: number): Promise<MonitorWithChecks[]>;
|
findByIdsWithChecks(monitorIds: string[], checksCount?: number): Promise<Monitor[]>;
|
||||||
|
|
||||||
// update
|
// update
|
||||||
updateById(monitorId: string, teamId: string, updates: Partial<Monitor>): Promise<Monitor>;
|
updateById(monitorId: string, teamId: string, updates: Partial<Monitor>): Promise<Monitor>;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { MonitorModel } from "@/db/models/index.js";
|
import { MonitorModel } from "@/db/models/index.js";
|
||||||
import type { MonitorDocument, CheckSnapshotDocument } from "@/db/models/index.js";
|
import type { MonitorDocument, CheckSnapshotDocument } from "@/db/models/index.js";
|
||||||
import type { Monitor, MonitorsSummary, MonitorWithChecks, CheckSnapshot, Check } from "@/types/index.js";
|
import type { Monitor, MonitorsSummary, CheckSnapshot, Check } from "@/types/index.js";
|
||||||
import mongoose, { type FilterQuery, type PipelineStage } from "mongoose";
|
import mongoose, { type FilterQuery, type PipelineStage } from "mongoose";
|
||||||
import type { IMonitorsRepository, TeamQueryConfig, SummaryConfig } from "./IMonitorsRepository.js";
|
import type { IMonitorsRepository, TeamQueryConfig, SummaryConfig } from "./IMonitorsRepository.js";
|
||||||
import { AppError } from "@/utils/AppError.js";
|
import { AppError } from "@/utils/AppError.js";
|
||||||
@@ -79,7 +79,7 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
|||||||
return this.mapDocuments(monitors);
|
return this.mapDocuments(monitors);
|
||||||
};
|
};
|
||||||
|
|
||||||
findByIdsWithChecks = async (monitorIds: string[], checksCount: number = 25): Promise<MonitorWithChecks[]> => {
|
findByIdsWithChecks = async (monitorIds: string[], checksCount: number = 25): Promise<Monitor[]> => {
|
||||||
if (!monitorIds.length) {
|
if (!monitorIds.length) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@@ -315,7 +315,7 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
private toEntityWithChecks = (doc: any): MonitorWithChecks => {
|
private toEntityWithChecks = (doc: any): Monitor => {
|
||||||
const toStringId = (value: unknown): string => {
|
const toStringId = (value: unknown): string => {
|
||||||
if (value instanceof mongoose.Types.ObjectId) {
|
if (value instanceof mongoose.Types.ObjectId) {
|
||||||
return value.toString();
|
return value.toString();
|
||||||
@@ -396,7 +396,6 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
|||||||
recentChecks: (doc.recentChecks ?? []).map((check: any) => this.toCheckSnapshot(check)),
|
recentChecks: (doc.recentChecks ?? []).map((check: any) => this.toCheckSnapshot(check)),
|
||||||
createdAt: toDateString(doc.createdAt),
|
createdAt: toDateString(doc.createdAt),
|
||||||
updatedAt: toDateString(doc.updatedAt),
|
updatedAt: toDateString(doc.updatedAt),
|
||||||
checks,
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -363,15 +363,10 @@ export class MonitorService implements IMonitorService {
|
|||||||
const monitorsWithChecks = monitorsList.map((monitor: Monitor) => {
|
const monitorsWithChecks = monitorsList.map((monitor: Monitor) => {
|
||||||
const rawChecks = monitor.recentChecks ?? [];
|
const rawChecks = monitor.recentChecks ?? [];
|
||||||
const isSnapshotType = snapshotOnlyRequest || snapshotTypes.includes(monitor.type);
|
const isSnapshotType = snapshotOnlyRequest || snapshotTypes.includes(monitor.type);
|
||||||
// recentChecks are stored oldest-first, reverse to get newest-first for display
|
const checks = isSnapshotType ? rawChecks.slice(0, 1) : NormalizeData(rawChecks, 10, 100);
|
||||||
const reversedChecks = [...rawChecks].reverse();
|
monitor.recentChecks = checks;
|
||||||
const checks = isSnapshotType ? reversedChecks.slice(0, 1) : NormalizeData(reversedChecks, 10, 100);
|
return monitor;
|
||||||
return {
|
|
||||||
...monitor,
|
|
||||||
checks,
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return { summary: summary ?? null, count, monitors: monitorsWithChecks };
|
return { summary: summary ?? null, count, monitors: monitorsWithChecks };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -189,3 +189,5 @@ export type NormalizedCheck<T extends HasResponseTime = Check> = T & {
|
|||||||
export type NormalizedUptimeCheck<T extends GroupedCheck = GroupedCheck> = T & {
|
export type NormalizedUptimeCheck<T extends GroupedCheck = GroupedCheck> = T & {
|
||||||
originalAvgResponseTime: number;
|
originalAvgResponseTime: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type CheckSnapshot = Omit<Check, "metadata" | "ack" | "ackAt" | "expiry" | "__v" | "updatedAt">;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { Check } from "@/types/check.js";
|
import type { Check } from "@/types/check.js";
|
||||||
|
import type { CheckSnapshot } from "@/types/check.js";
|
||||||
export type CheckSnapshot = Omit<Check, "metadata" | "ack" | "ackAt" | "expiry" | "__v" | "updatedAt">;
|
export type { CheckSnapshot } from "@/types/check.js";
|
||||||
|
|
||||||
export const MonitorTypes = ["http", "ping", "pagespeed", "hardware", "docker", "port", "game", "unknown"] as const;
|
export const MonitorTypes = ["http", "ping", "pagespeed", "hardware", "docker", "port", "game", "unknown"] as const;
|
||||||
export type MonitorType = (typeof MonitorTypes)[number];
|
export type MonitorType = (typeof MonitorTypes)[number];
|
||||||
@@ -57,14 +57,10 @@ export interface MonitorsSummary {
|
|||||||
pausedMonitors: number;
|
pausedMonitors: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MonitorWithChecks extends Monitor {
|
|
||||||
checks: Check[] | CheckSnapshot[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface MonitorsWithChecksByTeamIdResult {
|
export interface MonitorsWithChecksByTeamIdResult {
|
||||||
summary: MonitorsSummary | null;
|
summary: MonitorsSummary | null;
|
||||||
count: number;
|
count: number;
|
||||||
monitors: MonitorWithChecks[];
|
monitors: Monitor[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UptimeDetailsResult {
|
export interface UptimeDetailsResult {
|
||||||
|
|||||||
Reference in new issue
Block a user