-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsysinfo.js
More file actions
37 lines (34 loc) · 819 Bytes
/
sysinfo.js
File metadata and controls
37 lines (34 loc) · 819 Bytes
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
var http = require('http');
var url = require('url');
var os = require('os');
var host = '0.0.0.0';
var port = 8080;
var srv = http.createServer(function (req, res) {
var sysinfo = {};
var arg = url.parse(req.url, true).query;
switch(arg.index){
case 'MEM': {
sysinfo= {'MEM': os.totalmem()};
break;
}
case 'LOADAVG':{
sysinfo = {'LOADAVG':os.loadavg()};
break;
}
case 'HOSTNAME':{
sysinfo = {'HOSTNAME':os.hostname()};
break;
}
case 'UPTIME':{
sysinfo = {'UPTIME': os.uptime()};
break;
}
default:
sysinfo = {};
}
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(JSON.stringify(sysinfo));
});
srv.listen(port, host, function() {
console.log('listening on http://%s:%d',host,port);
});