-
Notifications
You must be signed in to change notification settings - Fork 0
/
monode.js
32 lines (31 loc) · 921 Bytes
/
monode.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
const conf = require('./conf.js')
const os = require('os')
const disk = require('diskusage')
const socket = require('socket.io-client')(conf.server + ":" + conf.socket_port)
console.log(`MoNode want: ${conf.server + ":" + conf.socket_port}`)
var stats
socket.on('connect', () => {
console.log("-> Connection succesful!")
stats = setInterval(() => {
disk.check("/", (err, info) => {
if (err) console.error(err)
socket.emit('stats', {
key: conf.key,
date: new Date(),
hostname: os.hostname(),
freemem: os.freemem(),
totalmem: os.totalmem(),
loadavg: os.loadavg(),
network: os.networkInterfaces(),
platform: os.platform(),
relase: os.release(),
uptime: os.uptime(),
diskusage: info
})
})
}, 2500)
})
socket.on('disconnect', () => {
clearInterval(stats)
console.log(`<- Disconnected from server`)
})