diff options
Diffstat (limited to 'app.js')
-rw-r--r-- | app.js | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -2,6 +2,25 @@ var os = require('os'); var http = require('http'); var ps = require('portscanner'); var dispatcher = require('httpdispatcher'); +var spawn = require('child_process').spawn; + +function getmem(){ + var prc = spawn('free', []); + + prc.stdout.setEncoding('utf8'); + prc.stdout.on('data', function (data) { + var str = data.toString() + var lines = str.split(/\n/g); + for(var i = 0; i < lines.length; i++) { + lines[i] = lines[i].split(/\s+/); + } + serverstat.mem = lines[1][2]/lines[1][1]; + }); + + prc.on('close', function (code) { + }); +} + var PORT = 3369; var serverstat={ @@ -34,15 +53,15 @@ function refreshStat(){ else serverstat.mc=false; }) + getmem(); serverstat.uptime = os.uptime(); - serverstat.mem = 1 - os.freemem()/os.totalmem(); serverstat.load = os.loadavg(); } function handleRequest(request, response){ try { //log the request on console - console.log(request.url); +// console.log(request.url); //Disptach dispatcher.dispatch(request, response); } catch(err) { |