Skip to content

Commit

Permalink
load the index html for /status from proper path
Browse files Browse the repository at this point in the history
  • Loading branch information
capaj committed Aug 22, 2016
1 parent 1dddb31 commit 1df3bf9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
21 changes: 11 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion sample/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 === '/') {
Expand Down

0 comments on commit 1df3bf9

Please # to comment.