-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.js
54 lines (51 loc) · 1.12 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
var Int64 = require('node-cint64').Int64
var active_metrics = []
class Integer {
constructor(name) {
this.name = name
this.memory = null
active_metrics.push(this)
}
getSize() {
return 8;
}
getType() {
return "level 8 signed";
}
setMemory(buf) {
this.memory = buf
}
set(val) {
if (!this.memory) return;
new Int64(val).intoBuffer(this.memory)
}
incr(val=1) {
if (!this.memory) return;
new Int64(this.memory).add(val).intoBuffer(this.memory)
}
decr(val=1) {
if (!this.memory) return;
new Int64(this.memory).sub(val).intoBuffer(this.memory)
}
}
class Counter {
constructor(name) {
this.name = name
this.memory = null
active_metrics.push(this)
}
getSize() {
return 8;
}
getType() {
return "counter 8";
}
setMemory(buf) {
this.memory = buf
}
incr(val=1) {
if (!this.memory) return;
new Int64(this.memory).add(val).intoBuffer(this.memory)
}
}
module.exports = { Integer, Counter, active_metrics };