Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Alert threshold for checkevents #91

Merged
merged 5 commits into from

2 participants

Commits on Jan 20, 2013
  1. @greggythefly

    adding alert threshold

    greggythefly authored committed
  2. @greggythefly

    adding alert threshold

    greggythefly authored committed
  3. @greggythefly

    adding alert threshold

    greggythefly authored committed
  4. @greggythefly

    adding alert threshold

    greggythefly authored committed
This page is out of date. Refresh to see the latest.
Showing with 60 additions and 5 deletions.
  1. +10 −1 app/dashboard/views/_checkDetails.ejs
  2. +50 −4 models/check.js
View
11 app/dashboard/views/_checkDetails.ejs
@@ -32,12 +32,21 @@
<label class="control-label">Slow threshold</label>
<div class="controls">
<div class="input-append">
- <input type="text" name="check[maxTime]" value="<%= check.maxTime %>" class="span2" />
+ <input type="text" name="check[maxTime]" value="<%= check.maxTime %>" class="span1" />
<span class="add-on">ms</span>
</div>
</div>
</div>
<div class="control-group">
+ <label class="control-label">Alert Treshold</label>
+ <div class="controls">
+ <div class="input-append">
+ <input type="text" name="check[nbErrors]" value="<%= check.nbErrors %>" class="span1" />
+ <span class="add-on">failed pings</span>
+ </div>
+ </div>
+ </div>
+ <div class="control-group">
<label class="control-label">Tags</label>
<div class="controls">
<textarea name="check[tags]" rows="2"/><%= check.tags.join(', ') %></textarea>
View
54 models/check.js
@@ -19,6 +19,8 @@ var Check = new Schema({
url : String,
interval : { type: Number, default: 60000 }, // interval between two pings
maxTime : { type: Number, default: 1500 }, // time under which a ping is considered responsive
+ alertTreshold : { type: Number, default: 1 }, // nb of errors from which to trigger a new CheckEvent
+ errorCount : { type: Number, default: 0 }, // count number of errors
tags : [String],
lastChanged : Date,
firstTested : Date,
@@ -73,11 +75,22 @@ Check.methods.togglePause = function() {
Check.methods.setLastTest = function(status, time, error) {
var now = time ? new Date(time) : new Date();
+ var mustNotifyEvent = this.mustNotifyEvent(status);
+
if (!this.firstTested) {
this.firstTested = now;
}
+
this.lastTested = now;
+
if (this.isUp != status) {
+ this.lastChanged = now;
+ this.isUp = status;
+ this.uptime = 0;
+ this.downtime = 0;
+ }
+
+ if (mustNotifyEvent) {
var event = new CheckEvent({
timestamp: now,
check: this,
@@ -90,10 +103,7 @@ Check.methods.setLastTest = function(status, time, error) {
event.downtime = now.getTime() - this.lastChanged.getTime();
}
event.save();
- this.lastChanged = now;
- this.isUp = status;
- this.uptime = 0;
- this.downtime = 0;
+ this.markEventNotified();
}
var durationSinceLastChange = now.getTime() - this.lastChanged.getTime();
if (status) {
@@ -104,6 +114,42 @@ Check.methods.setLastTest = function(status, time, error) {
return this;
};
+Check.methods.mustNotifyEvent = function(status) {
+ if (!this.firstTested) {
+ return true;
+ }
+ if (!status) {
+ // check is down
+ if (this.isUp != status) {
+ // check goes down for the first time
+ this.errorCount = 1;
+ }
+ if (this.errorCount < this.alertTreshold) {
+ // repeated down pings - increase error count until reaching the down alert treshold
+ this.errorCount++;
+ return false;
+ }
+ if (this.errorCount === this.alertTreshold) {
+ // enough down pings to trigger notofication
+ return true;
+ }
+ // error count higher than treshold, that means the alert was already sent
+ return false;
+ }
+ // check is up
+ if (this.isUp != status && this.errorCount > this.alertTreshold) {
+ // check goes up after reaching the down alert treshold before
+ return true;
+ }
+ // check either goes up after less than alertTreshold down pings, or is already up for long
+ return false;
+}
+
+Check.methods.markEventNotified = function() {
+ // increase error count to disable notification if the next ping has the same status
+ this.errorCount = this.alertTreshold + 1;
+}
+
Check.methods.getQosPercentage = function() {
if (!this.qos) return false;
return (this.qos.ups / this.qos.count) * 100;
Something went wrong with that request. Please try again.