Merge pull request #86 from Spiritreader/master

Implement retries (#56)
pull/103/head^2
Louis Lam 3 years ago committed by GitHub
commit 248b5292dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -11,3 +11,4 @@
LICENSE LICENSE
README.md README.md
.editorconfig .editorconfig
.vscode

1
.gitignore vendored

@ -7,3 +7,4 @@ dist-ssr
/data /data
!/data/.gitkeep !/data/.gitkeep
.vscode

Binary file not shown.

@ -0,0 +1,37 @@
-- You should not modify if this have pushed to Github, unless it does serious wrong with the db.
-- Add maxretries column to monitor
PRAGMA foreign_keys=off;
BEGIN TRANSACTION;
create table monitor_dg_tmp
(
id INTEGER not null
primary key autoincrement,
name VARCHAR(150),
active BOOLEAN default 1 not null,
user_id INTEGER
references user
on update cascade on delete set null,
interval INTEGER default 20 not null,
url TEXT,
type VARCHAR(20),
weight INTEGER default 2000,
hostname VARCHAR(255),
port INTEGER,
created_date DATETIME,
keyword VARCHAR(255),
maxretries INTEGER NOT NULL DEFAULT 0
);
insert into monitor_dg_tmp(id, name, active, user_id, interval, url, type, weight, hostname, port, created_date, keyword) select id, name, active, user_id, interval, url, type, weight, hostname, port, created_date, keyword from monitor;
drop table monitor;
alter table monitor_dg_tmp rename to monitor;
create index user_id on monitor (user_id);
COMMIT;
PRAGMA foreign_keys=on;

@ -16,7 +16,6 @@ const {Notification} = require("../notification")
* 1 = UP * 1 = UP
*/ */
class Monitor extends BeanModel { class Monitor extends BeanModel {
async toJSON() { async toJSON() {
let notificationIDList = {}; let notificationIDList = {};
@ -35,6 +34,7 @@ class Monitor extends BeanModel {
url: this.url, url: this.url,
hostname: this.hostname, hostname: this.hostname,
port: this.port, port: this.port,
maxretries: this.maxretries,
weight: this.weight, weight: this.weight,
active: this.active, active: this.active,
type: this.type, type: this.type,
@ -46,6 +46,7 @@ class Monitor extends BeanModel {
start(io) { start(io) {
let previousBeat = null; let previousBeat = null;
let retries = 0;
const beat = async () => { const beat = async () => {
if (! previousBeat) { if (! previousBeat) {
@ -107,12 +108,19 @@ class Monitor extends BeanModel {
bean.status = 1; bean.status = 1;
} }
retries = 0;
} catch (error) { } catch (error) {
if ((this.maxretries > 0) && (retries < this.maxretries)) {
retries++;
bean.status = 2;
}
bean.msg = error.message; bean.msg = error.message;
} }
// Mark as important if status changed // Mark as important if status changed, ignore pending pings,
if (! previousBeat || previousBeat.status !== bean.status) { // Don't notify if disrupted changes to up
if ((! previousBeat || previousBeat.status !== bean.status) && bean.status !== 2 && !(previousBeat.status === 2 && bean.status !== 0)) {
bean.important = true; bean.important = true;
// Do not send if first beat is UP // Do not send if first beat is UP
@ -237,7 +245,7 @@ class Monitor extends BeanModel {
} }
total += value; total += value;
if (row.status === 0) { if (row.status === 0 || row.status === 2) {
downtime += value; downtime += value;
} }
} }

@ -233,6 +233,7 @@ let needSetup = false;
bean.url = monitor.url bean.url = monitor.url
bean.interval = monitor.interval bean.interval = monitor.interval
bean.hostname = monitor.hostname; bean.hostname = monitor.hostname;
bean.maxretries = monitor.maxretries;
bean.port = monitor.port; bean.port = monitor.port;
bean.keyword = monitor.keyword; bean.keyword = monitor.keyword;

@ -1,7 +1,8 @@
$primary: #5CDD8B; $primary: #5CDD8B;
$danger: #DC3545; $danger: #DC3545;
$warning: #f8a306;
$link-color: #111; $link-color: #111;
$border-radius: 50rem; $border-radius: 50rem;
$highlight: #7ce8a4; $highlight: #7ce8a4;
$highlight-white: #e7faec; $highlight-white: #e7faec;

@ -3,7 +3,7 @@
<div class="hp-bar-big" :style="barStyle"> <div class="hp-bar-big" :style="barStyle">
<div <div
class="beat" class="beat"
:class="{ 'empty' : (beat === 0), 'down' : (beat.status === 0) }" :class="{ 'empty' : (beat === 0), 'down' : (beat.status === 0), 'pending' : (beat.status === 2) }"
:style="beatStyle" :style="beatStyle"
v-for="(beat, index) in shortBeatList" v-for="(beat, index) in shortBeatList"
:key="index" :key="index"
@ -166,6 +166,10 @@ export default {
background-color: $danger; background-color: $danger;
} }
&.pending {
background-color: $warning;
}
&:not(.empty):hover { &:not(.empty):hover {
transition: all ease-in-out 0.15s; transition: all ease-in-out 0.15s;
opacity: 0.8; opacity: 0.8;

@ -14,6 +14,8 @@ export default {
return "danger" return "danger"
} else if (this.status === 1) { } else if (this.status === 1) {
return "primary" return "primary"
} else if (this.status === 2) {
return "warning"
} else { } else {
return "secondary" return "secondary"
} }
@ -24,6 +26,8 @@ export default {
return "Down" return "Down"
} else if (this.status === 1) { } else if (this.status === 1) {
return "Up" return "Up"
} else if (this.status === 2) {
return "Pending"
} else { } else {
return "Unknown" return "Unknown"
} }
@ -34,6 +38,6 @@ export default {
<style scoped> <style scoped>
span { span {
width: 45px; width: 54px;
} }
</style> </style>

@ -30,6 +30,8 @@ export default {
return "danger" return "danger"
} else if (this.lastHeartBeat.status === 1) { } else if (this.lastHeartBeat.status === 1) {
return "primary" return "primary"
} else if (this.lastHeartBeat.status === 2) {
return "warning"
} else { } else {
return "secondary" return "secondary"
} }

@ -279,6 +279,11 @@ export default {
text: "Down", text: "Down",
color: "danger" color: "danger"
}; };
} else if (lastHeartBeat.status === 2) {
result[monitorID] = {
text: "Pending",
color: "warning"
};
} else { } else {
result[monitorID] = unknown; result[monitorID] = unknown;
} }

@ -110,6 +110,8 @@ export default {
result.up++; result.up++;
} else if (beat.status === 0) { } else if (beat.status === 0) {
result.down++; result.down++;
} else if (beat.status === 2) {
result.up++;
} else { } else {
result.unknown++; result.unknown++;
} }

@ -48,6 +48,12 @@
<input type="number" class="form-control" id="interval" v-model="monitor.interval" required min="20" step="1"> <input type="number" class="form-control" id="interval" v-model="monitor.interval" required min="20" step="1">
</div> </div>
<div class="mb-3">
<label for="maxRetries" class="form-label">Retries</label>
<input type="number" class="form-control" id="maxRetries" v-model="monitor.maxretries" required min="0" step="1">
<div class="form-text">Maximum retries before the service is marked as down and a notification is sent</div>
</div>
<div> <div>
<button class="btn btn-primary" type="submit" :disabled="processing">Save</button> <button class="btn btn-primary" type="submit" :disabled="processing">Save</button>
</div> </div>
@ -61,7 +67,7 @@
<h2>Notifications</h2> <h2>Notifications</h2>
<p v-if="$root.notificationList.length === 0">Not available, please setup.</p> <p v-if="$root.notificationList.length === 0">Not available, please setup.</p>
<div class="form-check form-switch mb-3" v-for="(notification, index) in $root.notificationList" :key="index"> <div class="form-check form-switch mb-3" :key="notification.id" v-for="notification in $root.notificationList">
<input class="form-check-input" type="checkbox" :id=" 'notification' + notification.id" v-model="monitor.notificationIDList[notification.id]"> <input class="form-check-input" type="checkbox" :id=" 'notification' + notification.id" v-model="monitor.notificationIDList[notification.id]">
<label class="form-check-label" :for=" 'notification' + notification.id"> <label class="form-check-label" :for=" 'notification' + notification.id">
@ -119,6 +125,7 @@ export default {
name: "", name: "",
url: "https://", url: "https://",
interval: 60, interval: 60,
maxretries: 0,
notificationIDList: {}, notificationIDList: {},
} }
} else if (this.isEdit) { } else if (this.isEdit) {

Loading…
Cancel
Save