Skip to content

Commit

Permalink
add retries for pinging function
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Spiritreader committed Jul 19, 2021
1 parent cbb9d3f commit a8b102a
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ dist-ssr

/data
!/data/.gitkeep
.vscode
Binary file modified db/kuma.db
Binary file not shown.
15 changes: 11 additions & 4 deletions server/model/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const {Notification} = require("../notification")
* 1 = UP
*/
class Monitor extends BeanModel {

async toJSON() {

let notificationIDList = {};
Expand All @@ -35,6 +34,7 @@ class Monitor extends BeanModel {
url: this.url,
hostname: this.hostname,
port: this.port,
maxretries: this.maxretries,
weight: this.weight,
active: this.active,
type: this.type,
Expand All @@ -46,6 +46,7 @@ class Monitor extends BeanModel {

start(io) {
let previousBeat = null;
let retries = 0;

const beat = async () => {
console.log(`Monitor ${this.id}: Heartbeat`)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -233,7 +240,7 @@ class Monitor extends BeanModel {
}

total += value;
if (row.status === 0) {
if (row.status === 0 || row.status === 2) {
downtime += value;
}
}
Expand Down
1 change: 1 addition & 0 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion src/assets/vars.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
$primary: #5CDD8B;
$danger: #DC3545;
$warning: #f8a306;
$link-color: #111;
$border-radius: 50rem;

$highlight: #7ce8a4;
$highlight-white: #e7faec;
$highlight-white: #e7faec;
6 changes: 5 additions & 1 deletion src/components/HeartbeatBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="hp-bar-big" :style="barStyle">
<div
class="beat"
:class="{ 'empty' : (beat === 0), 'down' : (beat.status === 0) }"
:class="{ 'empty' : (beat === 0), 'down' : (beat.status === 0), 'pending' : (beat.status === 2) }"
:style="beatStyle"
v-for="(beat, index) in shortBeatList"
:key="index"
Expand Down Expand Up @@ -166,6 +166,10 @@ export default {
background-color: $danger;
}
&.pending {
background-color: $warning;
}
&:not(.empty):hover {
transition: all ease-in-out 0.15s;
opacity: 0.8;
Expand Down
6 changes: 5 additions & 1 deletion src/components/Status.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export default {
return "danger"
} else if (this.status === 1) {
return "primary"
} else if (this.status === 2) {
return "warning"
} else {
return "secondary"
}
Expand All @@ -24,6 +26,8 @@ export default {
return "Down"
} else if (this.status === 1) {
return "Up"
} else if (this.status === 2) {
return "Pending"
} else {
return "Unknown"
}
Expand All @@ -34,6 +38,6 @@ export default {

<style scoped>
span {
width: 45px;
width: 54px;
}
</style>
2 changes: 2 additions & 0 deletions src/components/Uptime.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
5 changes: 5 additions & 0 deletions src/mixins/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/pages/DashboardHome.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down
8 changes: 7 additions & 1 deletion src/pages/EditMonitor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
<input type="number" class="form-control" id="interval" v-model="monitor.interval" required min="20" step="1">
</div>

<div class="mb-3">
<label for="interval" class="form-label">Retry Pings</label>
<input type="number" class="form-control" id="interval" v-model="monitor.maxretries" required min="0" step="1">
</div>

<div>
<button class="btn btn-primary" type="submit" :disabled="processing">Save</button>
</div>
Expand All @@ -61,7 +66,7 @@
<h2>Notifications</h2>
<p v-if="$root.notificationList.length === 0">Not available, please setup.</p>

<div class="form-check form-switch mb-3" v-for="notification in $root.notificationList">
<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]">

<label class="form-check-label" :for=" 'notification' + notification.id">
Expand Down Expand Up @@ -119,6 +124,7 @@ export default {
name: "",
url: "https://",
interval: 60,
maxretries: 0,
notificationIDList: {},
}
} else if (this.isEdit) {
Expand Down

0 comments on commit a8b102a

Please sign in to comment.