From d50bf206dea24e223ca57f92ec28daf2b6bbad37 Mon Sep 17 00:00:00 2001 From: Tuowen Zhao Date: Sat, 25 Jun 2016 22:01:34 -0600 Subject: switched to ExpressJS --- app.js | 239 +++++++++++++++++++++++++++----------------------------- config.js | 2 + numberlogger.js | 20 ++--- package.json | 9 ++- services.js | 1 - 5 files changed, 131 insertions(+), 140 deletions(-) create mode 100644 config.js delete mode 100644 services.js diff --git a/app.js b/app.js index 165dbeb..1f2a325 100644 --- a/app.js +++ b/app.js @@ -1,84 +1,93 @@ var os = require('os'); -var http = require('http'); var ps = require('portscanner'); -var dispatcher = require('httpdispatcher'); -var spawn = require('child_process').spawn; var nl = require('./numberlogger.js'); -var services = require('./services.js'); +var config = require('./config.js'); +var express = require('express'); +var compression = require('compression'); var PORT = 3369; -var logger = function(name,length) { +var serverstat = { + "uptime": os.uptime(), + "load": [0, 0, 0], + "services": {}, + "stats" : {} +}; + +var serverinfo = { + "hostname": os.hostname(), + "release": os.release(), + "cpuname": os.cpus()[0].model, + "cpunum": os.cpus().length, + "totmem": Math.round(os.totalmem()/1024/1024), + "desc" : config.description, + "stats": {} +}; + +var statResponse = {}; + +function checkp(key) { + ps.checkPortStatus(config.services[key], 'localhost', function (error, status) { + serverstat.services[key] = (status == 'open'); + }) +} + +var logger = function (name, length) { this.name = name; - this.sec = new nl(name+":sec",length); - this.min = new nl(name+":min",length); - this.hrs = new nl(name+":hrs",length); - this.day = new nl(name+":day",length); + this.sec = new nl(name + ":sec", length); + this.min = new nl(name + ":min", length); + this.hrs = new nl(name + ":hrs", length); + this.day = new nl(name + ":day", length); this.time = new Date(); -} +}; -logger.prototype.add = function(time,x) { - function average(l,n) { +logger.prototype.add = function (time, x) { + function average(l, n) { var sum = 0; - for (var i=0;i