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