From a8b102ad4a0f8a146af04fd12e17adce7ff3662f Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 19 Jul 2021 18:23:06 +0200 Subject: [PATCH 1/7] add retries for pinging function backend: - new field for monitor: maxretries - new pending status while service is retrying: 2 - pending status event is not marked important - pending pings however register as downtime in the calculation frontend: - added pending status while service is retrying - added color for new pending status - added field to configure amount of retries database: - IMPORTANT: THIS REQUIRES MIGRATION!!!! - added field: maxretries with default value 0 --- .gitignore | 1 + db/kuma.db | Bin 57344 -> 61440 bytes server/model/monitor.js | 15 +++++++++++---- server/server.js | 1 + src/assets/vars.scss | 3 ++- src/components/HeartbeatBar.vue | 6 +++++- src/components/Status.vue | 6 +++++- src/components/Uptime.vue | 2 ++ src/mixins/socket.js | 5 +++++ src/pages/DashboardHome.vue | 2 ++ src/pages/EditMonitor.vue | 8 +++++++- 11 files changed, 41 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 8d435974f..9caa313cb 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ dist-ssr /data !/data/.gitkeep +.vscode \ No newline at end of file diff --git a/db/kuma.db b/db/kuma.db index 07c93cf89abb94bac751a47894d5e0fff94aa17b..6e02ccc01fefc1d40029c18cbec08a6039cf723f 100644 GIT binary patch delta 1162 zcmd^9y>Hq;6t}@OU}Bu8Qcy*tT&yYrDQbX-p;K|;NZlHP%uyv1a>6Nb%U6s`5_KR$ zrHn0N>d=L?Q-!+s&*+%{phK8Cl-?O5l4k1Asgj?q`@PS5zxRCc&3|#_{}5YI7>1FE zh(uT-qruirLSY^~`7ZKPM&wi`(u+J4{o=LoShx=51Czj~fXX9IUHaY7oeG^fHJGA=#?SAyr3k7aBk> zA)r?^ZHwS7vx()?}&j!-7)P5J)GJN$Pam?mD+iN@p@|MV+?2 z@S~=OHZ~nxuhq$$WKF3>SV2m$Om(mE`DxoGSDs&N9;IoX+1Rly+;yvd(5G3;hFVmN zeeeSA$7!R0Qbi?ICw(nK9ntKCk^$9SeP%K5MFJSG01c?;U zpSiHiJRkc5>l_zZV~69-@O!qXNqm$rcw)8c_{^INk1F0JAKg!3n&4G7P+IAq;$Fd@8)myq~$1xGcFo zbGop9VV}$H$@ZTuWV4{aIo8P`Y^zy3c-X`@GqcOHur$Z9vTs)7?q{6*fs@U>Ait<2 zR>9LR#MRw3NJoK}OFI1xUs!gn0V828THM20&%AQ!C5!i&A10!W@H~ zJsg8Hj7&{6H#6}v39~T>Ffi~x-^``(fL~0Kv$Qz12 { console.log(`Monitor ${this.id}: Heartbeat`) @@ -109,12 +110,18 @@ class Monitor extends BeanModel { bean.status = 1; } + retries = 0; + } catch (error) { + if ((this.maxretries > 0) && (retries < this.maxretries)) { + retries++; + bean.status = 2; + } bean.msg = error.message; } - // Mark as important if status changed - if (! previousBeat || previousBeat.status !== bean.status) { + // Mark as important if status changed, ignore pending pings + if ((! previousBeat || previousBeat.status !== bean.status) && bean.status !== 2) { bean.important = true; // Do not send if first beat is UP @@ -233,7 +240,7 @@ class Monitor extends BeanModel { } total += value; - if (row.status === 0) { + if (row.status === 0 || row.status === 2) { downtime += value; } } diff --git a/server/server.js b/server/server.js index bd5894775..567ff490c 100644 --- a/server/server.js +++ b/server/server.js @@ -219,6 +219,7 @@ let needSetup = false; bean.url = monitor.url bean.interval = monitor.interval bean.hostname = monitor.hostname; + bean.maxretries = monitor.maxretries; bean.port = monitor.port; bean.keyword = monitor.keyword; diff --git a/src/assets/vars.scss b/src/assets/vars.scss index 31b0262d8..ebec378a5 100644 --- a/src/assets/vars.scss +++ b/src/assets/vars.scss @@ -1,7 +1,8 @@ $primary: #5CDD8B; $danger: #DC3545; +$warning: #f8a306; $link-color: #111; $border-radius: 50rem; $highlight: #7ce8a4; -$highlight-white: #e7faec; +$highlight-white: #e7faec; \ No newline at end of file diff --git a/src/components/HeartbeatBar.vue b/src/components/HeartbeatBar.vue index 48ffd2926..03cdceca6 100644 --- a/src/components/HeartbeatBar.vue +++ b/src/components/HeartbeatBar.vue @@ -3,7 +3,7 @@
span { - width: 45px; + width: 54px; } diff --git a/src/components/Uptime.vue b/src/components/Uptime.vue index ad8114fcb..322b35f70 100644 --- a/src/components/Uptime.vue +++ b/src/components/Uptime.vue @@ -30,6 +30,8 @@ export default { return "danger" } else if (this.lastHeartBeat.status === 1) { return "primary" + } else if (this.lastHeartBeat.status === 2) { + return "warning" } else { return "secondary" } diff --git a/src/mixins/socket.js b/src/mixins/socket.js index f0a3b1a6a..42de1eb3f 100644 --- a/src/mixins/socket.js +++ b/src/mixins/socket.js @@ -274,6 +274,11 @@ export default { text: "Down", color: "danger" }; + } else if (lastHeartBeat.status === 2) { + result[monitorID] = { + text: "Pending", + color: "warning" + }; } else { result[monitorID] = unknown; } diff --git a/src/pages/DashboardHome.vue b/src/pages/DashboardHome.vue index 820842bac..87380c7c2 100644 --- a/src/pages/DashboardHome.vue +++ b/src/pages/DashboardHome.vue @@ -90,6 +90,8 @@ export default { result.up++; } else if (beat.status === 0) { result.down++; + } else if (beat.status === 2) { + result.up++; } else { result.unknown++; } diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 01af50610..e4898c33d 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -48,6 +48,11 @@
+
+ + +
+
@@ -61,7 +66,7 @@

Notifications

Not available, please setup.

-
+
-
+
From 14e1d1f1057854ae7217a3028bca73aaf5da378e Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 20 Jul 2021 17:39:21 +0200 Subject: [PATCH 4/7] add .vscode directory to dockerignore --- .dockerignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.dockerignore b/.dockerignore index d439b2db5..825d58038 100644 --- a/.dockerignore +++ b/.dockerignore @@ -11,3 +11,4 @@ LICENSE README.md .editorconfig +.vscode From 32a5e838bab12dba60b825c3155344abcbef8579 Mon Sep 17 00:00:00 2001 From: LouisLam Date: Thu, 22 Jul 2021 17:44:59 +0800 Subject: [PATCH 5/7] add patch3.sql and fix duplicate id in EditMonitor.vue --- db/patch3.sql | 37 +++++++++++++++++++++++++++++++++++++ src/pages/EditMonitor.vue | 4 ++-- 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 db/patch3.sql diff --git a/db/patch3.sql b/db/patch3.sql new file mode 100644 index 000000000..e615632f9 --- /dev/null +++ b/db/patch3.sql @@ -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; diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index f5d71703a..69cd41625 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -49,8 +49,8 @@
- - + +
From 70b1f197c1a71d78e1c8b05a8269ef42e8264e8a Mon Sep 17 00:00:00 2001 From: LouisLam Date: Thu, 22 Jul 2021 19:02:44 +0800 Subject: [PATCH 6/7] rename "Retry Pings" to "Retries" --- src/pages/EditMonitor.vue | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 69cd41625..03fa66e95 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -49,8 +49,9 @@
- + +
Maximum retries before the service is marked as down and send notifications
From 5a219554b30322cce5620e75aa67b8199d04f10c Mon Sep 17 00:00:00 2001 From: LouisLam Date: Thu, 22 Jul 2021 19:49:46 +0800 Subject: [PATCH 7/7] grammar --- src/pages/EditMonitor.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 03fa66e95..75d7d4b9b 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -51,7 +51,7 @@
-
Maximum retries before the service is marked as down and send notifications
+
Maximum retries before the service is marked as down and a notification is sent