remove alertThreshold
This commit is contained in:
1 parent
a7b0ce4d8f
commit
2fb6cb0b6f
7 files changed
+17
-60
No files matched your search
@@ -83,10 +83,10 @@ export const useMonitorForm = ({
|
|||||||
type: "hardware",
|
type: "hardware",
|
||||||
url: data?.url || "",
|
url: data?.url || "",
|
||||||
secret: data?.secret || "",
|
secret: data?.secret || "",
|
||||||
cpuAlertThreshold: data?.cpuAlertThreshold ?? 80,
|
cpuAlertThreshold: data?.cpuAlertThreshold ?? 100,
|
||||||
memoryAlertThreshold: data?.memoryAlertThreshold ?? 80,
|
memoryAlertThreshold: data?.memoryAlertThreshold ?? 100,
|
||||||
diskAlertThreshold: data?.diskAlertThreshold ?? 80,
|
diskAlertThreshold: data?.diskAlertThreshold ?? 100,
|
||||||
tempAlertThreshold: data?.tempAlertThreshold ?? 80,
|
tempAlertThreshold: data?.tempAlertThreshold ?? 100,
|
||||||
selectedDisks: data?.selectedDisks || [],
|
selectedDisks: data?.selectedDisks || [],
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ export interface Monitor {
|
|||||||
uptimePercentage?: number;
|
uptimePercentage?: number;
|
||||||
notifications: string[];
|
notifications: string[];
|
||||||
secret?: string;
|
secret?: string;
|
||||||
alertThreshold: number;
|
|
||||||
cpuAlertThreshold: number;
|
cpuAlertThreshold: number;
|
||||||
memoryAlertThreshold: number;
|
memoryAlertThreshold: number;
|
||||||
diskAlertThreshold: number;
|
diskAlertThreshold: number;
|
||||||
|
|||||||
@@ -121,33 +121,21 @@ const MonitorSchema = new Schema<MonitorDocument>(
|
|||||||
secret: {
|
secret: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
alertThreshold: {
|
|
||||||
type: Number,
|
|
||||||
default: 5,
|
|
||||||
},
|
|
||||||
cpuAlertThreshold: {
|
cpuAlertThreshold: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: function () {
|
default: 100,
|
||||||
return this.alertThreshold;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
memoryAlertThreshold: {
|
memoryAlertThreshold: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: function () {
|
default: 100,
|
||||||
return this.alertThreshold;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
diskAlertThreshold: {
|
diskAlertThreshold: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: function () {
|
default: 100,
|
||||||
return this.alertThreshold;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
tempAlertThreshold: {
|
tempAlertThreshold: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: function () {
|
default: 100,
|
||||||
return this.alertThreshold;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
selectedDisks: {
|
selectedDisks: {
|
||||||
type: [String],
|
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 });
|
MonitorSchema.index({ teamId: 1, type: 1 });
|
||||||
|
|
||||||
const MonitorModel = model<MonitorDocument>("Monitor", MonitorSchema);
|
const MonitorModel = model<MonitorDocument>("Monitor", MonitorSchema);
|
||||||
|
|||||||
@@ -317,7 +317,6 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
|||||||
uptimePercentage: doc.uptimePercentage ?? undefined,
|
uptimePercentage: doc.uptimePercentage ?? undefined,
|
||||||
notifications: notificationIds,
|
notifications: notificationIds,
|
||||||
secret: doc.secret ?? undefined,
|
secret: doc.secret ?? undefined,
|
||||||
alertThreshold: doc.alertThreshold,
|
|
||||||
cpuAlertThreshold: doc.cpuAlertThreshold,
|
cpuAlertThreshold: doc.cpuAlertThreshold,
|
||||||
memoryAlertThreshold: doc.memoryAlertThreshold,
|
memoryAlertThreshold: doc.memoryAlertThreshold,
|
||||||
diskAlertThreshold: doc.diskAlertThreshold,
|
diskAlertThreshold: doc.diskAlertThreshold,
|
||||||
@@ -369,7 +368,6 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
|||||||
uptimePercentage: doc.uptimePercentage ?? undefined,
|
uptimePercentage: doc.uptimePercentage ?? undefined,
|
||||||
notifications: notificationIds,
|
notifications: notificationIds,
|
||||||
secret: doc.secret ?? undefined,
|
secret: doc.secret ?? undefined,
|
||||||
alertThreshold: doc.alertThreshold,
|
|
||||||
cpuAlertThreshold: doc.cpuAlertThreshold,
|
cpuAlertThreshold: doc.cpuAlertThreshold,
|
||||||
memoryAlertThreshold: doc.memoryAlertThreshold,
|
memoryAlertThreshold: doc.memoryAlertThreshold,
|
||||||
diskAlertThreshold: doc.diskAlertThreshold,
|
diskAlertThreshold: doc.diskAlertThreshold,
|
||||||
|
|||||||
@@ -269,10 +269,10 @@ class SuperSimpleQueueHelper {
|
|||||||
|
|
||||||
// Check if countdown has reached zero for any threshold
|
// Check if countdown has reached zero for any threshold
|
||||||
const shouldNotifyThreshold =
|
const shouldNotifyThreshold =
|
||||||
(breaches.cpu && (monitor.cpuAlertThreshold ?? monitor.alertThreshold) <= 0) ||
|
(breaches.cpu && (monitor.cpuAlertThreshold ?? 100) <= 0) ||
|
||||||
(breaches.memory && (monitor.memoryAlertThreshold ?? monitor.alertThreshold) <= 0) ||
|
(breaches.memory && (monitor.memoryAlertThreshold ?? 100) <= 0) ||
|
||||||
(breaches.disk && (monitor.diskAlertThreshold ?? monitor.alertThreshold) <= 0) ||
|
(breaches.disk && (monitor.diskAlertThreshold ?? 100) <= 0) ||
|
||||||
(breaches.temp && (monitor.tempAlertThreshold ?? monitor.alertThreshold) <= 0);
|
(breaches.temp && (monitor.tempAlertThreshold ?? 100) <= 0);
|
||||||
|
|
||||||
// Decision logic for hardware
|
// Decision logic for hardware
|
||||||
if (statusChanged && monitor.status === "down") {
|
if (statusChanged && monitor.status === "down") {
|
||||||
|
|||||||
@@ -88,12 +88,12 @@ export const buildHardwareAlerts = (
|
|||||||
const thresholdKey = alertThresholdKeyMap[type];
|
const thresholdKey = alertThresholdKeyMap[type];
|
||||||
// Iterate over each alert type to see if any need to be decremented
|
// Iterate over each alert type to see if any need to be decremented
|
||||||
if (alerts[type] === true) {
|
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
|
monitor[thresholdKey] = nextValue; // Decrement threshold if an alert is triggered
|
||||||
|
|
||||||
if (monitor[thresholdKey] <= 0) {
|
if (monitor[thresholdKey] <= 0) {
|
||||||
// If threshold drops below 0, reset and send notification
|
// If threshold drops below 0, reset and send notification
|
||||||
monitor[thresholdKey] = monitor.alertThreshold;
|
monitor[thresholdKey] = 100;
|
||||||
|
|
||||||
const formatAlert = {
|
const formatAlert = {
|
||||||
cpu: () => `Your current CPU usage (${(cpuUsage * 100).toFixed(0)}%) is above your threshold (${(cpuThreshold * 100).toFixed(0)}%)`,
|
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 { cpu: { usage_percent: cpuUsage = -1 } = {}, memory: { usage_percent: memoryUsage = -1 } = {}, disk = [] } = metrics;
|
||||||
|
|
||||||
const cpuBreach = cpuThreshold !== -1 && cpuUsage > cpuThreshold;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const memoryBreach = memoryThreshold !== -1 && memoryUsage > memoryThreshold;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const diskBreach = disk?.some((d) => diskThreshold !== -1 && typeof d?.usage_percent === "number" && d?.usage_percent > diskThreshold);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ export interface Monitor {
|
|||||||
uptimePercentage?: number;
|
uptimePercentage?: number;
|
||||||
notifications: string[];
|
notifications: string[];
|
||||||
secret?: string;
|
secret?: string;
|
||||||
alertThreshold: number;
|
|
||||||
cpuAlertThreshold: number;
|
cpuAlertThreshold: number;
|
||||||
memoryAlertThreshold: number;
|
memoryAlertThreshold: number;
|
||||||
diskAlertThreshold: number;
|
diskAlertThreshold: number;
|
||||||
|
|||||||
Reference in new issue
Block a user