remove unused checks
This commit is contained in:
1 parent
2fb6cb0b6f
commit
97ace1e058
2 files changed
+28
-49
No files matched your search
@@ -220,59 +220,38 @@ class SuperSimpleQueueHelper {
|
|||||||
return decision; // No metrics, can't evaluate
|
return decision; // No metrics, can't evaluate
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if thresholds exist
|
|
||||||
const hasThresholds =
|
|
||||||
monitor.cpuAlertThreshold !== undefined ||
|
|
||||||
monitor.memoryAlertThreshold !== undefined ||
|
|
||||||
monitor.diskAlertThreshold !== undefined ||
|
|
||||||
monitor.tempAlertThreshold !== undefined;
|
|
||||||
|
|
||||||
// Evaluate threshold breaches
|
// Evaluate threshold breaches
|
||||||
|
// CPU check
|
||||||
|
const cpuUsage = metrics.cpu?.usage_percent ?? -1;
|
||||||
|
const cpuBreach = cpuUsage !== -1 && cpuUsage > monitor.cpuAlertThreshold / 100;
|
||||||
|
|
||||||
|
// Memory check
|
||||||
|
const memoryUsage = metrics.memory?.usage_percent ?? -1;
|
||||||
|
const memoryBreach = memoryUsage !== -1 && memoryUsage > monitor.memoryAlertThreshold / 100;
|
||||||
|
|
||||||
|
// Disk check
|
||||||
|
const diskBreach =
|
||||||
|
metrics.disk?.some((d: any) => typeof d?.usage_percent === "number" && d.usage_percent > monitor.diskAlertThreshold / 100) ?? false;
|
||||||
|
|
||||||
|
// Temperature check (alert if ANY sensor exceeds threshold)
|
||||||
|
const temps = metrics.cpu?.temperature ?? [];
|
||||||
|
const tempBreach = temps.some((temp: number) => temp > monitor.tempAlertThreshold);
|
||||||
|
|
||||||
const breaches = {
|
const breaches = {
|
||||||
cpu: false,
|
cpu: cpuBreach,
|
||||||
memory: false,
|
memory: memoryBreach,
|
||||||
disk: false,
|
disk: diskBreach,
|
||||||
temp: false,
|
temp: tempBreach,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (hasThresholds) {
|
|
||||||
// CPU check
|
|
||||||
if (monitor.cpuAlertThreshold !== undefined) {
|
|
||||||
const cpuUsage = metrics.cpu?.usage_percent ?? -1;
|
|
||||||
// Convert threshold from percentage (0-100) to decimal (0-1) for comparison
|
|
||||||
breaches.cpu = cpuUsage !== -1 && cpuUsage > monitor.cpuAlertThreshold / 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Memory check
|
|
||||||
if (monitor.memoryAlertThreshold !== undefined) {
|
|
||||||
const memoryUsage = metrics.memory?.usage_percent ?? -1;
|
|
||||||
// Convert threshold from percentage (0-100) to decimal (0-1) for comparison
|
|
||||||
breaches.memory = memoryUsage !== -1 && memoryUsage > monitor.memoryAlertThreshold / 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disk check
|
|
||||||
if (monitor.diskAlertThreshold !== undefined) {
|
|
||||||
// Convert threshold from percentage (0-100) to decimal (0-1) for comparison
|
|
||||||
breaches.disk =
|
|
||||||
metrics.disk?.some((d: any) => typeof d?.usage_percent === "number" && d.usage_percent > monitor.diskAlertThreshold / 100) ?? false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Temperature check (alert if ANY sensor exceeds threshold)
|
|
||||||
if (monitor.tempAlertThreshold !== undefined) {
|
|
||||||
const temps = metrics.cpu?.temperature ?? [];
|
|
||||||
// Temperature threshold is in Celsius, compare directly
|
|
||||||
breaches.temp = temps.some((temp: number) => temp > monitor.tempAlertThreshold);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const anyThresholdBreached = Object.values(breaches).some((b) => b);
|
const anyThresholdBreached = Object.values(breaches).some((b) => b);
|
||||||
|
|
||||||
// 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 ?? 100) <= 0) ||
|
(breaches.cpu && monitor.cpuAlertThreshold <= 0) ||
|
||||||
(breaches.memory && (monitor.memoryAlertThreshold ?? 100) <= 0) ||
|
(breaches.memory && monitor.memoryAlertThreshold <= 0) ||
|
||||||
(breaches.disk && (monitor.diskAlertThreshold ?? 100) <= 0) ||
|
(breaches.disk && monitor.diskAlertThreshold <= 0) ||
|
||||||
(breaches.temp && (monitor.tempAlertThreshold ?? 100) <= 0);
|
(breaches.temp && monitor.tempAlertThreshold <= 0);
|
||||||
|
|
||||||
// Decision logic for hardware
|
// Decision logic for hardware
|
||||||
if (statusChanged && monitor.status === "down") {
|
if (statusChanged && monitor.status === "down") {
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ 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] ?? 100) as number) - 1;
|
const nextValue = monitor[thresholdKey] - 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) {
|
||||||
@@ -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 ?? 100) as number) - 1 <= 0) {
|
if (cpuBreach && monitor.cpuAlertThreshold - 1 <= 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const memoryBreach = memoryThreshold !== -1 && memoryUsage > memoryThreshold;
|
const memoryBreach = memoryThreshold !== -1 && memoryUsage > memoryThreshold;
|
||||||
if (memoryBreach && ((monitor.memoryAlertThreshold ?? 100) as number) - 1 <= 0) {
|
if (memoryBreach && monitor.memoryAlertThreshold - 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 ?? 100) as number) - 1 <= 0) {
|
if (diskBreach && monitor.diskAlertThreshold - 1 <= 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user