-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathMetrics.js
More file actions
43 lines (37 loc) · 1.09 KB
/
Copy pathMetrics.js
File metadata and controls
43 lines (37 loc) · 1.09 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
const libratoEnabled = Boolean(process.env.LIBRATO_USER);
const Metrics = {
increment(key, value, source) {
if (libratoEnabled && source) {
console.log(`source=${source} count#${key}=${value}`);
}
},
sample(key, value, source) {
if (libratoEnabled && source) {
console.log(`source=${source} sample#${key}=${value}`);
}
},
measure(key, value, source) {
if (libratoEnabled && source) {
console.log(`source=${source} measure#${key}=${value}`);
}
},
measureHrTime(key, value, source) {
const [seconds, nanoseconds] = value;
const msec = (seconds * 1000) + (nanoseconds / 1e6);
if (libratoEnabled && source) {
Metrics.measure(key, `${msec.toFixed(2)}ms`, source);
}
return msec;
},
async timing(key, source, createPromise, callback) {
const start = process.hrtime();
const result = await Promise.resolve(createPromise());
const end = process.hrtime(start);
const msec = Metrics.measureHrTime(key, end, source);
if (callback) {
callback(msec);
}
return result;
},
};
export default Metrics;