forked from Unitech/pm2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHttpInterface.js
62 lines (51 loc) · 1.5 KB
/
HttpInterface.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
//
// PM2 Monit and Server web interface
// Disserve JSON in light way
// by Strzelewicz Alexandre
//
var http = require('http');
var os = require('os');
var Satan = require('./Satan');
var urlT = require('url');
var cst = require('../constants.js');
var p = require('path');
http.createServer(function (req, res) {
// We always send json
res.writeHead(200, {'Content-Type': 'application/json'});
var path = urlT.parse(req.url).pathname;
console.log('Access on PM2 monit point %s', path);
if (path == '/') {
// Main monit route
Satan.executeRemote('list', {}, function(err, data_proc) {
var data = {
system_info: { hostname: os.hostname(),
uptime: os.uptime()
},
monit: { loadavg: os.loadavg(),
total_mem: os.totalmem(),
free_mem: os.freemem(),
cpu: os.cpus(),
interfaces: os.networkInterfaces()
},
processes: data_proc
};
res.write(JSON.stringify(data));
return res.end();
});
}
else {
// 404
res.write(JSON.stringify({err : '404'}));
return res.end();
};
}).listen(cst.WEB_INTERFACE);
// var MicroDB = require("nodejs-microdb");
// var fdb = new MicroDB({
// "file" : p.join(cst.DEFAULT_FILE_PATH, "monit.db")
// });
// setInterval(function() {
// Satan.executeRemote("list", {}, function(err, data_proc) {
// console.log('adding');
// fdb.add(data_proc);
// });
// }, 1000);