-
Notifications
You must be signed in to change notification settings - Fork 707
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug with separate monitor not aggregating qos scores
Separate Monitor class and configuration in two. Now the monitor only communicates with the REST API, and the checks themselves.
- Loading branch information
1 parent
d0afe4b
commit 874d72e
Showing
6 changed files
with
118 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* Module dependencies. | ||
*/ | ||
var Check = require('../models/check'), | ||
CheckEvent = require('../models/checkEvent'), | ||
Ping = require('../models/ping'); | ||
|
||
/** | ||
* Analyzer constructor | ||
* | ||
* The analyzer aggregates the ping data into QoS scores for checks and tags. | ||
* | ||
* The constructor expects a configuration object as parameter, with these properties: | ||
* updateInterval: Interval between each update of the QoS score in milliseconds, defaults to 1 minute | ||
* qosAggregationInterval: Interval between each daily and hourly aggregation the QoS score in milliseconds, defaults to 1 hour | ||
* oldestHistory: Oldest ping and checkEvent age to keep in milliseconds, defaults to 3 months | ||
* | ||
* @param {Object} Monitor configuration | ||
* @api public | ||
*/ | ||
function Analyzer(config) { | ||
config.updateInterval = config.updateInterval || 60 * 1000; | ||
config.qosAggregationInterval = config.qosAggregationInterval || 60 * 60 * 1000; | ||
config.oldestHistory = config.oldestHistory || 3 * 31 * 24 * 60 * 60 * 1000; | ||
this.config = config; | ||
} | ||
|
||
/** | ||
* Start the analysis of all checks. | ||
* | ||
* The polling actually starts after the pollingInterval set to the constructor. | ||
* | ||
* @api public | ||
*/ | ||
Analyzer.prototype.start = function() { | ||
// schedule updates | ||
this.intervalForUpdate = setInterval(this.updateAllChecks.bind(this), this.config.updateInterval); | ||
this.intervalForAggregation = setInterval(this.aggregateQos.bind(this), this.config.qosAggregationInterval); | ||
} | ||
|
||
/** | ||
* Stop the analysis of all checks | ||
* | ||
* @api public | ||
*/ | ||
Analyzer.prototype.stop = function() { | ||
clearInterval(this.intervalForUpdate); | ||
clearInterval(this.intervalForAggregation); | ||
} | ||
|
||
/** | ||
* Update the QoS scores for each check once | ||
* | ||
* @api private | ||
*/ | ||
Analyzer.prototype.updateAllChecks = function() { | ||
Ping.updateLast24HoursQos.apply(Ping); | ||
Ping.updateLastHourQos.apply(Ping); | ||
} | ||
|
||
/** | ||
* Aggregate the QoS scores for each check | ||
* | ||
* @api private | ||
*/ | ||
Analyzer.prototype.aggregateQos = function() { | ||
var CheckHourlyStat = require('../models/checkHourlyStat'); | ||
CheckHourlyStat.updateLastDayQos.apply(CheckHourlyStat); | ||
CheckHourlyStat.updateLastMonthQos.apply(CheckHourlyStat); | ||
var TagHourlyStat = require('../models/tagHourlyStat'); | ||
TagHourlyStat.updateLastDayQos.apply(TagHourlyStat); | ||
TagHourlyStat.updateLastMonthQos.apply(TagHourlyStat); | ||
Ping.cleanup(this.config.oldestHistory); | ||
CheckEvent.cleanup(this.config.oldestHistory); | ||
} | ||
|
||
/** | ||
* Create an analyzer to update the check and tag qos scores. | ||
* | ||
* Example: | ||
* | ||
* m = analyzer.createAnalyzer({ updateInterval: 60000}); | ||
* m.start(); | ||
* // the analysis starts, every 60 seconds | ||
* m.stop(); | ||
* | ||
* @param {Object} Configuration object | ||
* @api public | ||
*/ | ||
exports.createAnalyzer = function(config) { | ||
return new Analyzer(config); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters