remove alertThreshold

This commit is contained in:
Alex Holliday committed 2026-02-14 21:29:30 +00:00
1 parent a7b0ce4d8f
commit 2fb6cb0b6f
7 files changed
+17 -60

No files matched your search

+4 -4
View File
@@ -83,10 +83,10 @@ export const useMonitorForm = ({
type: "hardware",
url: data?.url || "",
secret: data?.secret || "",
cpuAlertThreshold: data?.cpuAlertThreshold ?? 80,
memoryAlertThreshold: data?.memoryAlertThreshold ?? 80,
diskAlertThreshold: data?.diskAlertThreshold ?? 80,
tempAlertThreshold: data?.tempAlertThreshold ?? 80,
cpuAlertThreshold: data?.cpuAlertThreshold ?? 100,
memoryAlertThreshold: data?.memoryAlertThreshold ?? 100,
diskAlertThreshold: data?.diskAlertThreshold ?? 100,
tempAlertThreshold: data?.tempAlertThreshold ?? 100,
selectedDisks: data?.selectedDisks || [],
};
break;
-1
View File
@@ -46,7 +46,6 @@ export interface Monitor {
uptimePercentage?: number;
notifications: string[];
secret?: string;
alertThreshold: number;
cpuAlertThreshold: number;
memoryAlertThreshold: number;
diskAlertThreshold: number;
+4 -43
View File
@@ -121,33 +121,21 @@ const MonitorSchema = new Schema<MonitorDocument>(
secret: {
type: String,
},
alertThreshold: {
type: Number,
default: 5,
},
cpuAlertThreshold: {
type: Number,
default: function () {
return this.alertThreshold;
},
default: 100,
},
memoryAlertThreshold: {
type: Number,
default: function () {
return this.alertThreshold;
},
default: 100,
},
diskAlertThreshold: {
type: Number,
default: function () {
return this.alertThreshold;
},
default: 100,
},
tempAlertThreshold: {
type: Number,
default: function () {
return this.alertThreshold;
},
default: 100,
},
selectedDisks: {
type: [String],
@@ -175,33 +163,6 @@ const MonitorSchema = new Schema<MonitorDocument>(
}
);
MonitorSchema.pre("save", function (next) {
if (!this.cpuAlertThreshold || this.isModified("alertThreshold")) {
this.cpuAlertThreshold = this.alertThreshold;
}
if (!this.memoryAlertThreshold || this.isModified("alertThreshold")) {
this.memoryAlertThreshold = this.alertThreshold;
}
if (!this.diskAlertThreshold || this.isModified("alertThreshold")) {
this.diskAlertThreshold = this.alertThreshold;
}
if (!this.tempAlertThreshold || this.isModified("alertThreshold")) {
this.tempAlertThreshold = this.alertThreshold;
}
next();
});
MonitorSchema.pre("findOneAndUpdate", function (next) {
const update = this.getUpdate() as UpdateQuery<MonitorDocument> | null;
if (update && !Array.isArray(update) && update.alertThreshold !== undefined) {
update.cpuAlertThreshold = update.alertThreshold;
update.memoryAlertThreshold = update.alertThreshold;
update.diskAlertThreshold = update.alertThreshold;
update.tempAlertThreshold = update.alertThreshold;
}
next();
});
MonitorSchema.index({ teamId: 1, type: 1 });
const MonitorModel = model<MonitorDocument>("Monitor", MonitorSchema);
@@ -317,7 +317,6 @@ class MongoMonitorsRepository implements IMonitorsRepository {
uptimePercentage: doc.uptimePercentage ?? undefined,
notifications: notificationIds,
secret: doc.secret ?? undefined,
alertThreshold: doc.alertThreshold,
cpuAlertThreshold: doc.cpuAlertThreshold,
memoryAlertThreshold: doc.memoryAlertThreshold,
diskAlertThreshold: doc.diskAlertThreshold,
@@ -369,7 +368,6 @@ class MongoMonitorsRepository implements IMonitorsRepository {
uptimePercentage: doc.uptimePercentage ?? undefined,
notifications: notificationIds,
secret: doc.secret ?? undefined,
alertThreshold: doc.alertThreshold,
cpuAlertThreshold: doc.cpuAlertThreshold,
memoryAlertThreshold: doc.memoryAlertThreshold,
diskAlertThreshold: doc.diskAlertThreshold,
@@ -269,10 +269,10 @@ class SuperSimpleQueueHelper {
// Check if countdown has reached zero for any threshold
const shouldNotifyThreshold =
(breaches.cpu && (monitor.cpuAlertThreshold ?? monitor.alertThreshold) <= 0) ||
(breaches.memory && (monitor.memoryAlertThreshold ?? monitor.alertThreshold) <= 0) ||
(breaches.disk && (monitor.diskAlertThreshold ?? monitor.alertThreshold) <= 0) ||
(breaches.temp && (monitor.tempAlertThreshold ?? monitor.alertThreshold) <= 0);
(breaches.cpu && (monitor.cpuAlertThreshold ?? 100) <= 0) ||
(breaches.memory && (monitor.memoryAlertThreshold ?? 100) <= 0) ||
(breaches.disk && (monitor.diskAlertThreshold ?? 100) <= 0) ||
(breaches.temp && (monitor.tempAlertThreshold ?? 100) <= 0);
// Decision logic for hardware
if (statusChanged && monitor.status === "down") {
@@ -88,12 +88,12 @@ export const buildHardwareAlerts = (
const thresholdKey = alertThresholdKeyMap[type];
// Iterate over each alert type to see if any need to be decremented
if (alerts[type] === true) {
const nextValue = ((monitor[thresholdKey] ?? monitor.alertThreshold) as number) - 1;
const nextValue = ((monitor[thresholdKey] ?? 100) as number) - 1;
monitor[thresholdKey] = nextValue; // Decrement threshold if an alert is triggered
if (monitor[thresholdKey] <= 0) {
// If threshold drops below 0, reset and send notification
monitor[thresholdKey] = monitor.alertThreshold;
monitor[thresholdKey] = 100;
const formatAlert = {
cpu: () => `Your current CPU usage (${(cpuUsage * 100).toFixed(0)}%) is above your threshold (${(cpuThreshold * 100).toFixed(0)}%)`,
@@ -136,17 +136,17 @@ export const shouldSendHardwareAlert = (monitor: Monitor, networkResponse: Monit
const { cpu: { usage_percent: cpuUsage = -1 } = {}, memory: { usage_percent: memoryUsage = -1 } = {}, disk = [] } = metrics;
const cpuBreach = cpuThreshold !== -1 && cpuUsage > cpuThreshold;
if (cpuBreach && ((monitor.cpuAlertThreshold ?? monitor.alertThreshold) as number) - 1 <= 0) {
if (cpuBreach && ((monitor.cpuAlertThreshold ?? 100) as number) - 1 <= 0) {
return true;
}
const memoryBreach = memoryThreshold !== -1 && memoryUsage > memoryThreshold;
if (memoryBreach && ((monitor.memoryAlertThreshold ?? monitor.alertThreshold) as number) - 1 <= 0) {
if (memoryBreach && ((monitor.memoryAlertThreshold ?? 100) as number) - 1 <= 0) {
return true;
}
const diskBreach = disk?.some((d) => diskThreshold !== -1 && typeof d?.usage_percent === "number" && d?.usage_percent > diskThreshold);
if (diskBreach && ((monitor.diskAlertThreshold ?? monitor.alertThreshold) as number) - 1 <= 0) {
if (diskBreach && ((monitor.diskAlertThreshold ?? 100) as number) - 1 <= 0) {
return true;
}
-1
View File
@@ -32,7 +32,6 @@ export interface Monitor {
uptimePercentage?: number;
notifications: string[];
secret?: string;
alertThreshold: number;
cpuAlertThreshold: number;
memoryAlertThreshold: number;
diskAlertThreshold: number;