29484dc7 by Jabis Sevon

downgraded to express@^3.23 and socket.io@^0.9.16

1 parent eec9eab8
index.rendered.html
node_modules
index.rendered.html
node_modules
examples/node_modules
......
### Issues with HTTPS (including Heroku) has been resolved, module is working again
# express-status-monitor
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.
![Monitoring Page](http://i.imgur.com/AHizEWq.gif "Monitoring Page")
## Installation & setup
1. Run `npm install express-status-monitor --save`
2. Before any other middleware or router add following line:
`app.use(require('express-status-monitor')());`
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: 5, // Every 5 seconds
retention: 60
}, {
interval: 15, // Every 15 seconds
retention: 60
}]
```
## License
[MIT License](https://opensource.org/licenses/MIT) © Rafal Wilinski
### Issues with HTTPS (including Heroku) has been resolved, module is working again
# express-status-monitor
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.
![Monitoring Page](http://i.imgur.com/AHizEWq.gif "Monitoring Page")
## Installation & setup
1. Run `npm install express-status-monitor --save`
2. Before any other middleware or router add following line:
`app.use(require('express-status-monitor')());`
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: 5, // Every 5 seconds
retention: 60
}, {
interval: 15, // Every 15 seconds
retention: 60
}]
```
## License
[MIT License](https://opensource.org/licenses/MIT) © Rafal Wilinski
......
const express = require('express');
const app = express();
const config = {
path: '/',
title: 'Express Status',
spans: [{
interval: 1,
retention: 60
}, {
interval: 5,
retention: 60
}, {
interval: 15,
retention: 60
}]
}
app.use(require('../index')(config));
app.listen(3000, () => {
console.log('🌏 http://0.0.0.0:3000');
});
const express = require('express');
const app = express();
const http = require('http');
const io = require('socket.io');
const config = {
uri: 'www.cert.coder.fi',
port: 4000,
path: '/',
title: 'Express Status',
spans: [{
interval: 1,
retention: 60
}, {
interval: 5,
retention: 60
}, {
interval: 15,
retention: 60
}]
}
var server = http.createServer(app);
app.use(require('../index')(config, server));
server.listen(config.port, config.uri, () => {
console.log('🌏 http://'+config.uri+':'+config.port);
});
......
{
"name": "express-status-monitor-example",
"version": "0.0.1",
"description": "Examples",
"main": "index.js",
"author": "Rafal Wilinski raf.wilinski@gmail.com",
"contributors": [
{
"name": "Julien Breux",
"email": "julien.breux@gmail.com",
"url": "https://github.com/JulienBreux/"
}
],
"license": "MIT",
"dependencies": {
"express": "^4.14.0",
"on-headers": "^1.0.1",
"pidusage": "^1.0.4",
"socket.io": "^1.4.8"
}
}
{
"name": "express-status-monitor-example",
"version": "0.0.1",
"description": "Examples",
"main": "index.js",
"author": "Rafal Wilinski raf.wilinski@gmail.com",
"contributors": [
{
"name": "Julien Breux",
"email": "julien.breux@gmail.com",
"url": "https://github.com/JulienBreux/"
},
{
"name": "Jabis Sevon",
"email": "jabis.is@gmail.com",
"url": "https://jscodex.com"
}
],
"license": "MIT",
"dependencies": {
"express": "^3.21.2",
"on-headers": "^1.0.1",
"pidusage": "^1.0.4",
"socket.io": "^0.9.16"
}
}
......
(function () {
'use strict';
const fs = require('fs');
const path = require('path');
const os = require('os');
const onHeaders = require('on-headers');
const pidusage = require('pidusage');
let io;
const defaultConfig = {
title: 'Express Status',
path: '/status',
spans: [{
interval: 1,
retention: 60
}, {
interval: 5,
retention: 60
}, {
interval: 15,
retention: 60
}]
};
const gatherOsMetrics = (io, span) => {
const defaultResponse = {
'2': 0,
'3': 0,
'4': 0,
'5': 0,
count: 0,
mean: 0,
timestamp: Date.now()
};
pidusage.stat(process.pid, (err, stat) => {
const last = span.responses[span.responses.length - 1];
// Convert from B to MB
stat.memory = stat.memory / 1024 / 1024;
stat.load = os.loadavg();
stat.timestamp = Date.now();
span.os.push(stat);
if (!span.responses[0] || last.timestamp + (span.interval * 1000) < Date.now()) span.responses.push(defaultResponse);
if (span.os.length >= span.retention) span.os.shift();
if (span.responses[0] && span.responses.length > span.retention) span.responses.shift();
sendMetrics(io, span);
});
};
const sendMetrics = (io, 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 = (config) => {
if (config === null || config === undefined) {
config = defaultConfig;
}
if (config.path === undefined || !config instanceof String) {
config.path = defaultConfig.path;
}
if (config.spans === undefined || !config instanceof Array) {
config.spans = defaultConfig.spans;
}
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);
io.on('connection', (socket) => {
socket.emit('start', config.spans);
socket.on('change', function() { socket.emit('start', config.spans); });
});
config.spans.forEach((span) => {
span.os = [];
span.responses = [];
setInterval(() => gatherOsMetrics(io, span), span.interval * 1000);
});
}
const startTime = process.hrtime();
if (req.path === config.path) {
res.send(renderedHtml);
} else {
onHeaders(res, () => {
const diff = process.hrtime(startTime);
const responseTime = diff[0] * 1e3 + diff[1] * 1e-6;
const category = Math.floor(res.statusCode / 100);
config.spans.forEach((span) => {
const last = span.responses[span.responses.length - 1];
if (last !== undefined &&
last.timestamp / 1000 + span.interval > Date.now() / 1000) {
last[category]++;
last.count++;
last.mean = last.mean + ((responseTime - last.mean) / last.count);
} else {
span.responses.push({
'2': category === 2 ? 1 : 0,
'3': category === 3 ? 1 : 0,
'4': category === 4 ? 1 : 0,
'5': category === 5 ? 1 : 0,
count: 1,
mean: responseTime,
timestamp: Date.now()
});
}
});
});
next();
}
};
};
module.exports = middlewareWrapper;
}());
(function() {
'use strict';
const fs = require('fs');
const path = require('path');
const os = require('os');
const onHeaders = require('on-headers');
const pidusage = require('pidusage');
let io;
const defaultConfig = {
uri: 'www.cert.coder.fi',
port: 4000,
title: 'Express Status',
path: '/status',
spans: [{
interval: 1,
retention: 60
}, {
interval: 5,
retention: 60
}, {
interval: 15,
retention: 60
}]
};
const gatherOsMetrics = (io, span) => {
const defaultResponse = {
'2': 0,
'3': 0,
'4': 0,
'5': 0,
count: 0,
mean: 0,
timestamp: Date.now()
};
pidusage.stat(process.pid, (err, stat) => {
const last = span.responses[span.responses.length - 1];
// Convert from B to MB
stat.memory = stat.memory / 1024 / 1024;
stat.load = os.loadavg();
stat.timestamp = Date.now();
span.os.push(stat);
if (!span.responses[0] || last.timestamp + (span.interval * 1000) < Date.now()) span.responses.push(defaultResponse);
if (span.os.length >= span.retention) span.os.shift();
if (span.responses[0] && span.responses.length > span.retention) span.responses.shift();
sendMetrics(io, span);
});
};
const sendMetrics = (io, 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 = (config, server) => {
if (config === null || config === undefined) {
config = defaultConfig;
}
if (config.path === undefined || !config instanceof String) {
config.path = defaultConfig.path;
}
if (config.spans === undefined || !config instanceof Array) {
config.spans = defaultConfig.spans;
}
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) {
//console.log(req)
io = require('socket.io').listen(server);
io.on('connection', (socket) => {
socket.emit('start', config.spans);
socket.on('change', function() {
socket.emit('start', config.spans);
});
});
config.spans.forEach((span) => {
span.os = [];
span.responses = [];
setInterval(() => gatherOsMetrics(io, span), span.interval * 1000);
});
}
const startTime = process.hrtime();
if (req.path === config.path) {
res.send(renderedHtml);
} else {
onHeaders(res, () => {
const diff = process.hrtime(startTime);
const responseTime = diff[0] * 1e3 + diff[1] * 1e-6;
const category = Math.floor(res.statusCode / 100);
config.spans.forEach((span) => {
const last = span.responses[span.responses.length - 1];
if (last !== undefined &&
last.timestamp / 1000 + span.interval > Date.now() / 1000) {
last[category]++;
last.count++;
last.mean = last.mean + ((responseTime - last.mean) / last.count);
} else {
span.responses.push({
'2': category === 2 ? 1 : 0,
'3': category === 3 ? 1 : 0,
'4': category === 4 ? 1 : 0,
'5': category === 5 ? 1 : 0,
count: 1,
mean: responseTime,
timestamp: Date.now()
});
}
});
});
next();
}
};
};
module.exports = middlewareWrapper;
}());
......
MIT License
Copyright (c) 2016 Rafal Wilinski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
MIT License
Copyright (c) 2016 Rafal Wilinski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
\ No newline at end of file
......
{
"name": "express-status-monitor",
"version": "0.0.10",
"description": "Realtime Monitoring for Express-based Node applications",
"main": "app.js",
"keywords": [
"node",
"status",
"monitoring",
"express",
"charts"
],
"author": "Rafal Wilinski <raf.wilinski@gmail.com> (http://rwilinski.me)",
"contributors": [
{
"name": "Julien Breux",
"email": "julien.breux@gmail.com",
"url": "https://github.com/JulienBreux/"
}
],
"repository": {
"type": "git",
"url": "https://github.com/RafalWilinski/express-status-monitor.git"
},
"license": "MIT",
"dependencies": {
"on-headers": "^1.0.1",
"pidusage": "^1.0.4",
"socket.io": "^1.4.8"
}
}
{
"name": "express-status-monitor",
"version": "0.0.10-dev",
"description": "Realtime Monitoring for Express-based Node applications",
"main": "app.js",
"keywords": [
"node",
"status",
"monitoring",
"express",
"charts"
],
"author": "Rafal Wilinski <raf.wilinski@gmail.com> (http://rwilinski.me)",
"contributors": [
{
"name": "Julien Breux",
"email": "julien.breux@gmail.com",
"url": "https://github.com/JulienBreux/"
},
{
"name": "Jabis Sevon",
"email": "jabis.is@gmail.com",
"url": "https://jscodex.com"
}
],
"repository": {
"type": "git",
"url": "https://github.com/RafalWilinski/express-status-monitor.git"
},
"license": "MIT",
"dependencies": {
"on-headers": "^1.0.1",
"pidusage": "^1.0.4",
"socket.io": "^0.9.17"
}
}
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!