-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor.js
More file actions
64 lines (50 loc) · 1.23 KB
/
monitor.js
File metadata and controls
64 lines (50 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*global module, require*/
/**
* Class for metrics
*/
var Monitor = function () {
this.results = {
connection : 0,
disconnection : 0,
errors : 0,
receiveMsg : 0,
heartbeat : 0,
};
this.messageCounter = 0;
this.counter = 0;
};
Monitor.prototype.connection = function () {
this.results.connection++;
this.counter++;
};
Monitor.prototype.disconnection = function () {
this.results.disconnection++;
this.counter++;
};
Monitor.prototype.errors = function () {
this.results.errors++;
this.counter++;
};
Monitor.prototype.receiveMsg = function () {
this.results.receiveMsg++;
this.messageCounter++;
};
Monitor.prototype.heartbeat = function () {
this.results.heartbeat++;
this.messageCounter++;
};
Monitor.prototype.reset = function() {
this.results.receiveMsg = 0;
}
/**
* Merge metrics
*/
Monitor.prototype.merge = function (monitor) {
this.results.connection += monitor.results.connection;
this.results.disconnection += monitor.results.disconnection;
this.results.errors += monitor.results.errors;
this.counter += monitor.counter;
this.messageCounter += monitor.messageCounter;
this.results.receiveMsg += monitor.results.receiveMsg;
};
module.exports = Monitor;