remove percentage to decimal conversion from BE
This commit is contained in:
1 parent
6337cd6462
commit
a5e918e0a7
1 file changed
+13
-19
@@ -86,19 +86,11 @@ class NotificationService {
|
|||||||
} = metrics;
|
} = metrics;
|
||||||
|
|
||||||
const alerts = {
|
const alerts = {
|
||||||
cpu:
|
cpu: cpuThreshold !== -1 && cpuUsage > cpuThreshold ? true : false,
|
||||||
cpuThreshold !== -1 && cpuUsage > cpuThreshold / 100
|
memory: memoryThreshold !== -1 && memoryUsage > memoryThreshold ? true : false,
|
||||||
? "CPU usage is above threshold"
|
disk: disk.some((d) => diskThreshold !== -1 && d.usage_percent > diskThreshold)
|
||||||
: null,
|
? true
|
||||||
memory:
|
: false,
|
||||||
memoryThreshold !== -1 && memoryUsage > memoryThreshold / 100
|
|
||||||
? "Memory usage is above threshold"
|
|
||||||
: null,
|
|
||||||
disk: disk.some(
|
|
||||||
(d) => diskThreshold !== -1 && d.usage_percent > diskThreshold / 100
|
|
||||||
)
|
|
||||||
? "Disk usage is above threshold"
|
|
||||||
: null,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const notifications = await this.db.getNotificationsByMonitorId(
|
const notifications = await this.db.getNotificationsByMonitorId(
|
||||||
@@ -110,7 +102,7 @@ class NotificationService {
|
|||||||
|
|
||||||
for (const type of alertTypes) {
|
for (const type of alertTypes) {
|
||||||
// Iterate over each alert type to see if any need to be decmremented
|
// Iterate over each alert type to see if any need to be decmremented
|
||||||
if (alerts[type] !== null) {
|
if (alerts[type] === true) {
|
||||||
notification[`${type}AlertThreshold`]--; // Decrement threshold if an alert is triggered
|
notification[`${type}AlertThreshold`]--; // Decrement threshold if an alert is triggered
|
||||||
|
|
||||||
if (notification[`${type}AlertThreshold`] <= 0) {
|
if (notification[`${type}AlertThreshold`] <= 0) {
|
||||||
@@ -119,13 +111,15 @@ class NotificationService {
|
|||||||
|
|
||||||
const formatAlert = {
|
const formatAlert = {
|
||||||
cpu: () =>
|
cpu: () =>
|
||||||
`${alerts.cpu} ${(cpuUsage * 100).toFixed(0)}% (${cpuThreshold}%)`,
|
`Your current CPU usage (${(cpuUsage * 100).toFixed(0)}%) is above your threshold (${(cpuThreshold * 100).toFixed(0)}%)`,
|
||||||
memory: () =>
|
memory: () =>
|
||||||
`${alerts.memory} ${(memoryUsage * 100).toFixed(0)}% (${memoryThreshold}%)`,
|
`Your current memory usage (${(memoryUsage * 100).toFixed(0)}%) is above your threshold (${(memoryThreshold * 100).toFixed(0)}%)`,
|
||||||
disk: () =>
|
disk: () =>
|
||||||
`${alerts.disk} ${disk
|
`Your current disk usage: ${disk
|
||||||
.map((d, idx) => `Disk${idx}: ${(d.usage_percent * 100).toFixed(0)}%`)
|
.map((d, idx) => `(Disk${idx}: ${(d.usage_percent * 100).toFixed(0)}%)`)
|
||||||
.join(", ")} (${diskThreshold}%)`,
|
.join(
|
||||||
|
", "
|
||||||
|
)} is above your threshold (${(diskThreshold * 100).toFixed(0)}%)`,
|
||||||
};
|
};
|
||||||
|
|
||||||
alertsToSend.push(formatAlert[type]());
|
alertsToSend.push(formatAlert[type]());
|
||||||
|
|||||||
Reference in new issue
Block a user