express-status-monitor
Advanced tools
Comparing version 0.0.9 to 0.0.10
30
index.js
@@ -12,2 +12,3 @@ (function () { | ||
const defaultConfig = { | ||
title: 'Express Status', | ||
path: '/status', | ||
@@ -26,6 +27,2 @@ spans: [{ | ||
Array.prototype.last = function() { | ||
return this[this.length - 1]; | ||
}; | ||
const gatherOsMetrics = (io, span) => { | ||
@@ -43,3 +40,3 @@ const defaultResponse = { | ||
pidusage.stat(process.pid, (err, stat) => { | ||
const last = span.responses[span.responses.length - 1]; | ||
// Convert from B to MB | ||
@@ -51,3 +48,3 @@ stat.memory = stat.memory / 1024 / 1024; | ||
span.os.push(stat); | ||
if (!span.responses[0] || span.responses.last().timestamp + (span.interval * 1000) < Date.now()) span.responses.push(defaultResponse); | ||
if (!span.responses[0] || last.timestamp + (span.interval * 1000) < Date.now()) span.responses.push(defaultResponse); | ||
@@ -83,5 +80,14 @@ if (span.os.length >= span.retention) span.os.shift(); | ||
if (config.title === undefined || !config instanceof String) { | ||
config.title = 'Express Status'; | ||
} | ||
let renderedHtml; | ||
fs.readFile(path.join(__dirname, '/index.html'), function(err, html){ | ||
renderedHtml = html.toString().replace(/{{title}}/g, config.title); | ||
}); | ||
return (req, res, next) => { | ||
if (io === null || io === undefined) { | ||
io = require('socket.io')(req.socket.server); | ||
@@ -103,3 +109,3 @@ | ||
if (req.path === config.path) { | ||
res.sendFile(path.join(__dirname + '/index.html')); | ||
res.send(renderedHtml); | ||
} else { | ||
@@ -114,6 +120,6 @@ onHeaders(res, () => { | ||
if (last !== undefined && | ||
span.responses.last().timestamp / 1000 + span.interval > Date.now() / 1000) { | ||
span.responses.last()[category]++; | ||
span.responses.last().count++; | ||
span.responses.last().mean = span.responses.last().mean + ((responseTime - span.responses.last().mean) / span.responses.last().count); | ||
last.timestamp / 1000 + span.interval > Date.now() / 1000) { | ||
last[category]++; | ||
last.count++; | ||
last.mean = last.mean + ((responseTime - last.mean) / last.count); | ||
} else { | ||
@@ -120,0 +126,0 @@ span.responses.push({ |
{ | ||
"name": "express-status-monitor", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"description": "Monitoring for Express-based Node applications", | ||
@@ -14,2 +14,9 @@ "main": "app.js", | ||
"author": "Rafal Wilinski raf.wilinski@gmail.com", | ||
"contributors": [ | ||
{ | ||
"name": "Julien Breux", | ||
"email": "julien.breux@gmail.com", | ||
"url": "https://github.com/JulienBreux/" | ||
} | ||
], | ||
"license": "MIT", | ||
@@ -16,0 +23,0 @@ "dependencies": { |
@@ -0,1 +1,2 @@ | ||
### Issues with HTTPS (including Heroku) has been resolved, module is working again | ||
# express-status-monitor | ||
@@ -8,21 +9,29 @@ Simple, self-hosted module based on Socket.io and Chart.js to report realtime server metrics for Express-based node servers. More Node frameworks coming soon. | ||
1. Run `npm install express-status-monitor --save` | ||
2. Before any other middleware or router add following line: | ||
2. Before any other middleware or router add following line: | ||
`app.use(require('express-status-monitor')());` | ||
3. Run server and to go `/status` | ||
3. Run server and go to `/status` | ||
## Run examples | ||
1. Go to `examples/` | ||
2. Run `npm install` | ||
3. Run server `node index.js` | ||
4. Go to `http://0.0.0.0:3000` | ||
## Options | ||
Monitor can be configured by passing options object into `expressMonitor` constructor. | ||
Default config: | ||
``` | ||
title: 'Express Status', // Default title | ||
path: '/status', | ||
spans: [{ | ||
interval: 1, // Every second | ||
retention: 60 // Keep 60 datapoints in memory | ||
interval: 1, // Every second | ||
retention: 60 // Keep 60 datapoints in memory | ||
}, { | ||
interval: 5, // Every 5 seconds | ||
interval: 5, // Every 5 seconds | ||
retention: 60 | ||
}, { | ||
interval: 15, // Every 15 seconds | ||
interval: 15, // Every 15 seconds | ||
retention: 60 | ||
@@ -29,0 +38,0 @@ }] |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17428
8
137
44