-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (49 loc) · 1.33 KB
/
index.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
const {
availableParallelism, cpus, freemem, loadavg, totalmem, uptime
} = require('os')
const pidusage = require('pidusage')
module.exports = function({observer})
{
async function getStats()
{
// TODO: provide stats of real Mediasoup Workers, not only for the Mafalda
// ones
const pidusages = workersPids?.length
? await pidusage(workersPids)
: undefined
return {
os: {
availableParallelism: availableParallelism(),
cpus: cpus(),
freemem: freemem(),
loadavg: loadavg(),
totalmem: totalmem(),
uptime: uptime()
},
pidusages,
process: {
constrainedMemory: process.constrainedMemory(),
cpuUsage: process.cpuUsage(),
hrtime: process.hrtime.bigint(),
memoryUsage: process.memoryUsage(),
resourceUsage: process.resourceUsage(),
uptime: process.uptime()
}
}
}
function onNewWorker({observer, pid})
{
if(workersPids.includes(pid)) return
workersPids.push(pid)
observer.once('close', function()
{
const index = workersPids.indexOf(pid)
if(index !== -1) workersPids.splice(index, 1)
})
}
const close = observer
.on('newworker', onNewWorker)
.off.bind(observer, 'newworker', onNewWorker)
const workersPids = []
return {close, getStats}
}