add monitor thresholds

This commit is contained in:
Alex Holliday committed 2025-12-04 21:52:50 +00:00
1 parent ba6c9a481d
commit 75ef6c934d
3 files changed
+28

No files matched your search

+19
View File
@@ -19,6 +19,13 @@ export const MonitorStatuses = [
] as const;
export type MonitorStatus = (typeof MonitorStatuses)[number];
export interface IMonitorThresholds {
cpu?: number;
memory?: number;
disk?: number;
temperature?: number;
}
export interface IMonitor extends Document {
_id: Types.ObjectId;
orgId: Types.ObjectId;
@@ -32,6 +39,7 @@ export interface IMonitor extends Document {
rejectUnauthorized: boolean;
status: MonitorStatus;
n: number; // Number of consecutive successes required to change status
thresholds?: IMonitorThresholds;
lastCheckedAt?: Date;
latestChecks: {
status: MonitorStatus;
@@ -45,6 +53,16 @@ export interface IMonitor extends Document {
updatedAt: Date;
}
const ThresholdsSchema = new Schema<IMonitorThresholds>(
{
cpu: { type: Number, min: 0, max: 100 },
memory: { type: Number, min: 0, max: 100 },
disk: { type: Number, min: 0, max: 100 },
temperature: { type: Number, min: -50, max: 150 },
},
{ _id: false }
);
const MonitorSchema = new Schema<IMonitor>(
{
orgId: { type: Schema.Types.ObjectId, ref: "Org", required: true },
@@ -67,6 +85,7 @@ const MonitorSchema = new Schema<IMonitor>(
enum: MonitorStatuses,
},
n: { type: Number, required: true, default: 1 },
thresholds: { type: ThresholdsSchema, required: false, default: undefined },
lastCheckedAt: { type: Date },
latestChecks: {
type: [
@@ -646,6 +646,7 @@ class MonitorService implements IMonitorService {
"rejectUnauthorized",
"n",
"notificationChannels",
"thresholds",
];
const safeUpdate: Partial<IMonitor> = {};
+8
View File
@@ -62,6 +62,14 @@ export const monitorSchema = z
secret: z.string().optional(),
interval: z.number({ message: "Interval required" }),
rejectUnauthorized: z.boolean().default(true),
thresholds: z
.object({
cpu: z.number().min(0).max(100).optional(),
memory: z.number().min(0).max(100).optional(),
disk: z.number().min(0).max(100).optional(),
temperature: z.number().min(0).max(150).optional(),
})
.optional(),
})
.superRefine((data, ctx) => {
const minIntervals: Record<string, number> = {