Merge pull request #380 from No0Vad/retry-heartbeat-interval

Added support for a retry interval to monitors
This commit is contained in:
Louis Lam
2021-09-16 00:21:53 +08:00
committed by GitHub
6 changed files with 36 additions and 4 deletions

View File

@@ -31,6 +31,7 @@ class Database {
"patch-setting-value-type.sql": true,
"patch-improve-performance.sql": true,
"patch-2fa.sql": true,
"patch-add-retry-interval-monitor.sql": true,
}
/**

View File

@@ -45,6 +45,7 @@ class Monitor extends BeanModel {
active: this.active,
type: this.type,
interval: this.interval,
retryInterval: this.retryInterval,
keyword: this.keyword,
ignoreTls: this.getIgnoreTls(),
upsideDown: this.isUpsideDown(),
@@ -296,12 +297,17 @@ class Monitor extends BeanModel {
bean.important = false;
}
let beatInterval = this.interval;
if (bean.status === UP) {
console.info(`Monitor #${this.id} '${this.name}': Successful Response: ${bean.ping} ms | Interval: ${this.interval} seconds | Type: ${this.type}`)
console.info(`Monitor #${this.id} '${this.name}': Successful Response: ${bean.ping} ms | Interval: ${beatInterval} seconds | Type: ${this.type}`)
} else if (bean.status === PENDING) {
console.warn(`Monitor #${this.id} '${this.name}': Pending: ${bean.msg} | Max retries: ${this.maxretries} | Type: ${this.type}`)
if (this.retryInterval !== this.interval) {
beatInterval = this.retryInterval;
}
console.warn(`Monitor #${this.id} '${this.name}': Pending: ${bean.msg} | Max retries: ${this.maxretries} | Retry: ${retries} | Retry Interval: ${beatInterval} seconds | Type: ${this.type}`)
} else {
console.warn(`Monitor #${this.id} '${this.name}': Failing: ${bean.msg} | Type: ${this.type}`)
console.warn(`Monitor #${this.id} '${this.name}': Failing: ${bean.msg} | Interval: ${beatInterval} seconds | Type: ${this.type}`)
}
io.to(this.user_id).emit("heartbeat", bean.toJSON());
@@ -313,7 +319,7 @@ class Monitor extends BeanModel {
previousBeat = bean;
if (! this.isStop) {
this.heartbeatInterval = setTimeout(beat, this.interval * 1000);
this.heartbeatInterval = setTimeout(beat, beatInterval * 1000);
}
}

View File

@@ -487,6 +487,7 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString();
bean.type = monitor.type
bean.url = monitor.url
bean.interval = monitor.interval
bean.retryInterval = monitor.retryInterval;
bean.hostname = monitor.hostname;
bean.maxretries = monitor.maxretries;
bean.port = monitor.port;