/
stats-manager-bap.js
73 lines (54 loc) · 1.41 KB
/
stats-manager-bap.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"use strict";
// Config consts and defaults
const CFG_INTERVAL = "interval";
const CFG_INTERVAL_DEFAULT = 0;
class StatsManagerBap extends besh.Bap {
constructor(name) {
super(name);
this.log.info("Initialising ...");
this.interval = this.getCfg(CFG_INTERVAL, CFG_INTERVAL_DEFAULT);
this.log.info(`${CFG_INTERVAL} set to (${this.interval}) secs`);
this.log.info("Finished initialising");
}
async start() {
this.log.info("Starting ...");
if (this.interval > 0) {
this.timeout = setInterval(
this.publish.bind(this), this.interval*1000);
}
this.log.info("Started!");
}
async stop() {
this.log.info("Stopping ...!");
this.publish();
if (this.interval > 0) {
clearInterval(this.timeout);
this.log.info("Stopped interval timer");
}
this.log.info("Stopped!");
}
publish() {
let bapList = besh.getBapList();
let now = Date.now();
bapList.forEach((bap) => {
let stats = bap.stats.get(now);
if (stats !== null) {
this.log.info("%j", stats);
}
});
}
get() {
let allStats = [];
let bapList = besh.getBapList();
bapList.forEach((bap) => {
let stats = bap.stats.get();
if (stats !== null) {
allStats.push(stats);
}
});
return allStats;
}
}
// Use the same version as besh
StatsManagerBap.version = besh.version;
module.exports = StatsManagerBap;