From 1df3bf9a9b429b2781f7073f4045e28d5f118a0c Mon Sep 17 00:00:00 2001 From: Jiri Spac Date: Mon, 22 Aug 2016 09:03:23 +0200 Subject: [PATCH] load the index html for /status from proper path --- index.js | 21 +++++++++++---------- package.json | 2 +- sample/server.js | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 278508c..aed0712 100644 --- a/index.js +++ b/index.js @@ -42,6 +42,15 @@ const gatherOsMetrics = (io, span) => { timestamp: Date.now() } + const sendMetrics = (span) => { + io.emit('stats', { + os: span.os[span.os.length - 2], + responses: span.responses[span.responses.length - 2], + interval: span.interval, + retention: span.retention + }) + } + pidusage.stat(process.pid, (err, stat) => { stat.memory = stat.memory / 1024 / 1024 // Convert from B to MB stat.load = os.loadavg() @@ -57,20 +66,12 @@ const gatherOsMetrics = (io, span) => { }) } -const sendMetrics = (span) => { - io.emit('stats', { - os: span.os[span.os.length - 2], - responses: span.responses[span.responses.length - 2], - interval: span.interval, - retention: span.retention - }) -} - const middlewareWrapper = (app, config) => { io = require('socket.io')(app) Object.assign(defaultConfig, config) config = defaultConfig - const indexHtml = fs.readFileSync('index.html', {'encoding': 'utf8'}) + const statusHtmlPage = config.statusHtmlPage || 'node_modules/koa-monitor/index.html' + const indexHtml = fs.readFileSync(statusHtmlPage, {'encoding': 'utf8'}) const template = handlebars.compile(indexHtml) io.on('connection', (socket) => { diff --git a/package.json b/package.json index a7fbc80..3009fe7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "koa-monitor", - "version": "0.1.1", + "version": "0.2.0", "description": "Realtime monitoring for koa-based Node applications", "main": "index.js", "keywords": [ diff --git a/sample/server.js b/sample/server.js index 16bdcbf..bce6b99 100644 --- a/sample/server.js +++ b/sample/server.js @@ -2,7 +2,7 @@ const app = require('koa')() const http = require('http') const monitor = require('../index.js') const server = http.createServer(app.callback()) -app.use(monitor(server, {path: '/status'})) +app.use(monitor(server, {path: '/status', statusHtmlPage: 'index.html'})) app.use(function *() { if (this.path === '/') {