mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-03-05 00:44:46 +00:00
ESLint fixes
This commit is contained in:
parent
d3709802c5
commit
9dd577dc98
3 changed files with 21 additions and 19 deletions
|
@ -1,7 +1,7 @@
|
||||||
exports.up = function (knex) {
|
exports.up = function (knex) {
|
||||||
// add various slow_response_notification parameters
|
// add various slow_response_notification parameters
|
||||||
return knex.schema
|
return knex.schema
|
||||||
.alterTable("monitor", function(table) {
|
.alterTable("monitor", function (table) {
|
||||||
table.boolean("slow_response_notification").notNullable().defaultTo(false);
|
table.boolean("slow_response_notification").notNullable().defaultTo(false);
|
||||||
table.string("slow_response_notification_method").notNullable().defaultTo("average");
|
table.string("slow_response_notification_method").notNullable().defaultTo("average");
|
||||||
table.integer("slow_response_notification_range").notNullable().defaultTo(300);
|
table.integer("slow_response_notification_range").notNullable().defaultTo(300);
|
||||||
|
@ -10,15 +10,15 @@ exports.up = function (knex) {
|
||||||
table.float("slow_response_notification_threshold_multiplier").notNullable().defaultTo(5.0);
|
table.float("slow_response_notification_threshold_multiplier").notNullable().defaultTo(5.0);
|
||||||
table.integer("slow_response_notification_resend_interval").notNullable().defaultTo(0);
|
table.integer("slow_response_notification_resend_interval").notNullable().defaultTo(0);
|
||||||
})
|
})
|
||||||
.alterTable("heartbeat", function(table) {
|
.alterTable("heartbeat", function (table) {
|
||||||
table.integer("slow_response_count").notNullable().defaultTo(0);
|
table.integer("slow_response_count").notNullable().defaultTo(0);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
exports.down = function (knex) {
|
exports.down = function (knex) {
|
||||||
// remove various slow_response_notification parameters
|
// remove various slow_response_notification parameters
|
||||||
return knex.schema
|
return knex.schema
|
||||||
.alterTable("monitor", function(table) {
|
.alterTable("monitor", function (table) {
|
||||||
table.dropColumn("slow_response_notification");
|
table.dropColumn("slow_response_notification");
|
||||||
table.dropColumn("slow_response_notification_method");
|
table.dropColumn("slow_response_notification_method");
|
||||||
table.dropColumn("slow_response_notification_range");
|
table.dropColumn("slow_response_notification_range");
|
||||||
|
@ -27,7 +27,7 @@ exports.down = function (knex) {
|
||||||
table.dropColumn("slow_response_notification_threshold_multiplier");
|
table.dropColumn("slow_response_notification_threshold_multiplier");
|
||||||
table.dropColumn("slow_response_notification_resend_interval");
|
table.dropColumn("slow_response_notification_resend_interval");
|
||||||
})
|
})
|
||||||
.alterTable("heartbeat", function(table) {
|
.alterTable("heartbeat", function (table) {
|
||||||
table.dropColumn("slow_response_count");
|
table.dropColumn("slow_response_count");
|
||||||
});
|
});
|
||||||
}
|
};
|
|
@ -307,7 +307,7 @@ class Monitor extends BeanModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the slow response notification enabled?
|
* Is the slow response notification enabled?
|
||||||
* @returns {boolean}
|
* @returns {boolean} Slow response notification is enabled?
|
||||||
*/
|
*/
|
||||||
isEnabledSlowResponseNotification() {
|
isEnabledSlowResponseNotification() {
|
||||||
return Boolean(this.slowResponseNotification);
|
return Boolean(this.slowResponseNotification);
|
||||||
|
@ -1444,7 +1444,7 @@ class Monitor extends BeanModel {
|
||||||
let actualResponseTime = 0;
|
let actualResponseTime = 0;
|
||||||
|
|
||||||
let previousBeats;
|
let previousBeats;
|
||||||
if (method != "last") {
|
if (method !== "last") {
|
||||||
//Get recent heartbeat list with range of time
|
//Get recent heartbeat list with range of time
|
||||||
const afterThisDate = new Date(Date.now() - (1000 * (monitor.slowResponseNotificationRange + 1))); // add 1 second otherwise we grab 0 previous beats when Time Range == Heartbeat Interval
|
const afterThisDate = new Date(Date.now() - (1000 * (monitor.slowResponseNotificationRange + 1))); // add 1 second otherwise we grab 0 previous beats when Time Range == Heartbeat Interval
|
||||||
previousBeats = await R.getAll(`
|
previousBeats = await R.getAll(`
|
||||||
|
@ -1482,6 +1482,8 @@ class Monitor extends BeanModel {
|
||||||
|
|
||||||
let threshold;
|
let threshold;
|
||||||
let thresholdDescription;
|
let thresholdDescription;
|
||||||
|
let afterThisDate;
|
||||||
|
let avgPing;
|
||||||
switch (thresholdMethod) {
|
switch (thresholdMethod) {
|
||||||
case "threshold-static":
|
case "threshold-static":
|
||||||
threshold = monitor.slowResponseNotificationThreshold;
|
threshold = monitor.slowResponseNotificationThreshold;
|
||||||
|
@ -1490,8 +1492,8 @@ class Monitor extends BeanModel {
|
||||||
|
|
||||||
case "threshold-relative-24-hour":
|
case "threshold-relative-24-hour":
|
||||||
//Get average response time over last 24 hours
|
//Get average response time over last 24 hours
|
||||||
const afterThisDate = new Date(Date.now() - (1000 * (24 * 60 * 60))); // 24 hours in milliseconds
|
afterThisDate = new Date(Date.now() - (1000 * (24 * 60 * 60))); // 24 hours in milliseconds
|
||||||
const avgPing = parseInt(await R.getCell(`
|
avgPing = parseInt(await R.getCell(`
|
||||||
SELECT AVG(ping) FROM heartbeat
|
SELECT AVG(ping) FROM heartbeat
|
||||||
WHERE time > datetime(?)
|
WHERE time > datetime(?)
|
||||||
AND ping IS NOT NULL
|
AND ping IS NOT NULL
|
||||||
|
@ -1511,12 +1513,12 @@ class Monitor extends BeanModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create stats to append to messages/logs
|
// Create stats to append to messages/logs
|
||||||
const methodDescription = ["average", "max"].includes(method) ? `${method} of ${windowDuration}s` : method;
|
const methodDescription = [ "average", "max" ].includes(method) ? `${method} of ${windowDuration}s` : method;
|
||||||
let msgStats = `Response: ${actualResponseTime}ms (${methodDescription}) | Threshold: ${threshold}ms (${thresholdDescription})`
|
let msgStats = `Response: ${actualResponseTime}ms (${methodDescription}) | Threshold: ${threshold}ms (${thresholdDescription})`;
|
||||||
// Add window duration for methods that make sense
|
// Add window duration for methods that make sense
|
||||||
|
|
||||||
// Verify valid response time was calculated
|
// Verify valid response time was calculated
|
||||||
if (actualResponseTime == 0 || !Number.isInteger(actualResponseTime)) {
|
if (actualResponseTime === 0 || !Number.isInteger(actualResponseTime)) {
|
||||||
log.debug("monitor", `[${this.name}] Failed to calculate valid response time`);
|
log.debug("monitor", `[${this.name}] Failed to calculate valid response time`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1529,7 +1531,7 @@ class Monitor extends BeanModel {
|
||||||
|
|
||||||
// Responding normally
|
// Responding normally
|
||||||
if (actualResponseTime < threshold) {
|
if (actualResponseTime < threshold) {
|
||||||
if (bean.slowResponseCount == 0) {
|
if (bean.slowResponseCount === 0) {
|
||||||
log.debug("monitor", `[${this.name}] Responding normally. No need to send slow response notification | ${msgStats}`);
|
log.debug("monitor", `[${this.name}] Responding normally. No need to send slow response notification | ${msgStats}`);
|
||||||
} else {
|
} else {
|
||||||
msgStats += ` | Slow for: ${bean.slowResponseCount * monitor.interval}s`;
|
msgStats += ` | Slow for: ${bean.slowResponseCount * monitor.interval}s`;
|
||||||
|
@ -1546,13 +1548,13 @@ class Monitor extends BeanModel {
|
||||||
++bean.slowResponseCount;
|
++bean.slowResponseCount;
|
||||||
|
|
||||||
// Always send first notification
|
// Always send first notification
|
||||||
if (bean.slowResponseCount == 1) {
|
if (bean.slowResponseCount === 1) {
|
||||||
log.debug("monitor", `[${this.name}] Responded slowly, sending notification | ${msgStats}`);
|
log.debug("monitor", `[${this.name}] Responded slowly, sending notification | ${msgStats}`);
|
||||||
let msg = `[${this.name}] Responded Slowly \n${msgStats}`;
|
let msg = `[${this.name}] Responded Slowly \n${msgStats}`;
|
||||||
Monitor.sendSlowResponseNotification(monitor, bean, msg);
|
Monitor.sendSlowResponseNotification(monitor, bean, msg);
|
||||||
// Send notification every x times
|
// Send notification every x times
|
||||||
} else if (this.slowResponseNotificationResendInterval > 0){
|
} else if (this.slowResponseNotificationResendInterval > 0) {
|
||||||
if (((bean.slowResponseCount) % this.slowResponseNotificationResendInterval) == 0) {
|
if (((bean.slowResponseCount) % this.slowResponseNotificationResendInterval) === 0) {
|
||||||
// Send notification again, because we are still responding slow
|
// Send notification again, because we are still responding slow
|
||||||
msgStats += ` | Slow for: ${bean.slowResponseCount * monitor.interval}s`;
|
msgStats += ` | Slow for: ${bean.slowResponseCount * monitor.interval}s`;
|
||||||
log.debug("monitor", `[${this.name}] Still responding slowly, sendSlowResponseNotification again | ${msgStats}`);
|
log.debug("monitor", `[${this.name}] Still responding slowly, sendSlowResponseNotification again | ${msgStats}`);
|
||||||
|
|
|
@ -978,7 +978,7 @@ const monitorDefaults = {
|
||||||
slowResponseNotification: false,
|
slowResponseNotification: false,
|
||||||
slowResponseNotificationMethod: "average",
|
slowResponseNotificationMethod: "average",
|
||||||
slowResponseNotificationRange: 300,
|
slowResponseNotificationRange: 300,
|
||||||
slowResponseNotificationThresholdMethod:"threshold-relative-24-hour",
|
slowResponseNotificationThresholdMethod: "threshold-relative-24-hour",
|
||||||
slowResponseNotificationThreshold: 2500,
|
slowResponseNotificationThreshold: 2500,
|
||||||
slowResponseNotificationThresholdMultiplier: 5.0,
|
slowResponseNotificationThresholdMultiplier: 5.0,
|
||||||
slowResponseNotificationResendInterval: 0,
|
slowResponseNotificationResendInterval: 0,
|
||||||
|
|
Loading…
Add table
Reference in a new issue