c34978d7 by Rafal Wilinski Committed by GitHub

Merge pull request #25 from JulienBreux/feature/title-and-example

[Feature] Add title config and examples
2 parents beb988f1 798f0645
index.rendered.html
/node_modules/
\ No newline at end of file
node_modules
......
......@@ -6,25 +6,33 @@ Simple, self-hosted module based on Socket.io and Chart.js to report realtime se
## Installation & setup
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 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
}]
......
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');
});
{
"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"
}
}
......@@ -9,6 +9,7 @@
let io;
const defaultConfig = {
title: 'Express Status',
path: '/status',
spans: [{
interval: 1,
......@@ -91,7 +92,12 @@
const startTime = process.hrtime();
if (req.path === config.path) {
res.sendFile(path.join(__dirname + '/index.html'));
fs.readFile(path.join(__dirname + '/index.html'), function(err, content) {
content = content.toString().replace(new RegExp(defaultConfig.title, 'g'), config.title);
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(content);
res.end();
});
} else {
onHeaders(res, () => {
const diff = process.hrtime(startTime);
......
......@@ -11,6 +11,13 @@
"charts"
],
"author": "Rafal Wilinski raf.wilinski@gmail.com",
"contributors": [
{
"name": "Julien Breux",
"email": "julien.breux@gmail.com",
"url": "https://github.com/JulienBreux/"
}
],
"license": "MIT",
"dependencies": {
"on-headers": "^1.0.1",
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!