forked from lynckia/licode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherizoAgentReporter.js
64 lines (48 loc) · 1.14 KB
/
erizoAgentReporter.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
/* global require, exports */
const os = require('os');
exports.Reporter = (spec) => {
const that = {};
const myId = spec.id;
const myMeta = spec.metadata || {};
let lastTotal = 0;
let lastIdle = 0;
const getStats = () => {
const cpus = os.cpus();
let user = 0;
let nice = 0;
let sys = 0;
let idle = 0;
let irq = 0;
let total = 0;
let cpu = 0;
cpus.forEach((singleCpuInfo) => {
user += singleCpuInfo.times.user;
nice += singleCpuInfo.times.nice;
sys += singleCpuInfo.times.sys;
irq += singleCpuInfo.times.irq;
idle += singleCpuInfo.times.idle;
});
total = user + nice + sys + idle + irq;
cpu = 1 - ((idle - lastIdle) / (total - lastTotal));
const mem = 1 - (os.freemem() / os.totalmem());
lastTotal = total;
lastIdle = idle;
const data = {
perc_cpu: cpu,
perc_mem: mem,
};
return data;
};
that.getErizoAgent = (callback) => {
const data = {
info: {
id: myId,
rpc_id: `ErizoAgent_${myId}`,
},
metadata: myMeta,
stats: getStats(),
};
callback(data);
};
return that;
};