Skip to content

Commit 1df3bf9

Browse files
committed
load the index html for /status from proper path
1 parent 1dddb31 commit 1df3bf9

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

index.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ const gatherOsMetrics = (io, span) => {
4242
timestamp: Date.now()
4343
}
4444

45+
const sendMetrics = (span) => {
46+
io.emit('stats', {
47+
os: span.os[span.os.length - 2],
48+
responses: span.responses[span.responses.length - 2],
49+
interval: span.interval,
50+
retention: span.retention
51+
})
52+
}
53+
4554
pidusage.stat(process.pid, (err, stat) => {
4655
stat.memory = stat.memory / 1024 / 1024 // Convert from B to MB
4756
stat.load = os.loadavg()
@@ -57,20 +66,12 @@ const gatherOsMetrics = (io, span) => {
5766
})
5867
}
5968

60-
const sendMetrics = (span) => {
61-
io.emit('stats', {
62-
os: span.os[span.os.length - 2],
63-
responses: span.responses[span.responses.length - 2],
64-
interval: span.interval,
65-
retention: span.retention
66-
})
67-
}
68-
6969
const middlewareWrapper = (app, config) => {
7070
io = require('socket.io')(app)
7171
Object.assign(defaultConfig, config)
7272
config = defaultConfig
73-
const indexHtml = fs.readFileSync('index.html', {'encoding': 'utf8'})
73+
const statusHtmlPage = config.statusHtmlPage || 'node_modules/koa-monitor/index.html'
74+
const indexHtml = fs.readFileSync(statusHtmlPage, {'encoding': 'utf8'})
7475
const template = handlebars.compile(indexHtml)
7576

7677
io.on('connection', (socket) => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "koa-monitor",
3-
"version": "0.1.1",
3+
"version": "0.2.0",
44
"description": "Realtime monitoring for koa-based Node applications",
55
"main": "index.js",
66
"keywords": [

sample/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const app = require('koa')()
22
const http = require('http')
33
const monitor = require('../index.js')
44
const server = http.createServer(app.callback())
5-
app.use(monitor(server, {path: '/status'}))
5+
app.use(monitor(server, {path: '/status', statusHtmlPage: 'index.html'}))
66

77
app.use(function *() {
88
if (this.path === '/') {

0 commit comments

Comments
 (0)