forked from observing/thor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.js
58 lines (48 loc) · 1.07 KB
/
metrics.js
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
'use strict';
function Metrics(requests) {
this.requests = requests;
this.connections = 0;
this.disconnects = 0;
this.errors = Object.create(null);
this.timing = Object.create(null);
}
/**
* The metrics has started collecting.
*
* @api private
*/
Metrics.prototype.start = function start() {
this.timing.start = Date.now();
return this;
};
/**
* The metrics has stopped collecting.
*
* @api private
*/
Metrics.prototype.stop = function stop() {
this.timing.stop = Date.now();
this.timing.duration = this.timing.stop - this.timing.start;
return this;
};
Metrics.prototype.ready = function open() {
this.timing.ready = Date.now();
this.timing.handshaken = this.timing.ready - this.timing.start;
};
/**
* Log an new error.
*
* @param {String} err Error message
* @api private
*/
Metrics.prototype.error = function error(err) {
if (!err) return this.errors;
var collection = this.errors[err];
if (!collection) this.errors[err] = 1;
else this.errors[err]++;
return this;
};
//
// Expose the metrics constructor.
//
module.exports = Metrics;