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
1 index.rendered.html 1 index.rendered.html
2 /node_modules/
...\ No newline at end of file ...\ No newline at end of file
2 node_modules
......
...@@ -10,12 +10,20 @@ Simple, self-hosted module based on Socket.io and Chart.js to report realtime se ...@@ -10,12 +10,20 @@ Simple, self-hosted module based on Socket.io and Chart.js to report realtime se
10 `app.use(require('express-status-monitor')());` 10 `app.use(require('express-status-monitor')());`
11 3. Run server and go to `/status` 11 3. Run server and go to `/status`
12 12
13 ## Run examples
14
15 1. Go to `examples/`
16 2. Run `npm install`
17 3. Run server `node index.js`
18 4. Go to `http://0.0.0.0:3000`
19
13 ## Options 20 ## Options
14 21
15 Monitor can be configured by passing options object into `expressMonitor` constructor. 22 Monitor can be configured by passing options object into `expressMonitor` constructor.
16 23
17 Default config: 24 Default config:
18 ``` 25 ```
26 title: 'Express Status', // Default title
19 path: '/status', 27 path: '/status',
20 spans: [{ 28 spans: [{
21 interval: 1, // Every second 29 interval: 1, // Every second
......
1 const express = require('express');
2 const app = express();
3
4 const config = {
5 path: '/',
6 title: 'Express Status',
7 spans: [{
8 interval: 1,
9 retention: 60
10 }, {
11 interval: 5,
12 retention: 60
13 }, {
14 interval: 15,
15 retention: 60
16 }]
17 }
18
19 app.use(require('../index')(config));
20
21 app.listen(3000, () => {
22 console.log('🌏 http://0.0.0.0:3000');
23 });
1 {
2 "name": "express-status-monitor-example",
3 "version": "0.0.1",
4 "description": "Examples",
5 "main": "index.js",
6 "author": "Rafal Wilinski raf.wilinski@gmail.com",
7 "contributors": [
8 {
9 "name": "Julien Breux",
10 "email": "julien.breux@gmail.com",
11 "url": "https://github.com/JulienBreux/"
12 }
13 ],
14 "license": "MIT",
15 "dependencies": {
16 "express": "^4.14.0",
17 "on-headers": "^1.0.1",
18 "pidusage": "^1.0.4",
19 "socket.io": "^1.4.8"
20 }
21 }
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
9 let io; 9 let io;
10 10
11 const defaultConfig = { 11 const defaultConfig = {
12 title: 'Express Status',
12 path: '/status', 13 path: '/status',
13 spans: [{ 14 spans: [{
14 interval: 1, 15 interval: 1,
...@@ -91,7 +92,12 @@ ...@@ -91,7 +92,12 @@
91 92
92 const startTime = process.hrtime(); 93 const startTime = process.hrtime();
93 if (req.path === config.path) { 94 if (req.path === config.path) {
94 res.sendFile(path.join(__dirname + '/index.html')); 95 fs.readFile(path.join(__dirname + '/index.html'), function(err, content) {
96 content = content.toString().replace(new RegExp(defaultConfig.title, 'g'), config.title);
97 res.writeHead(200, {'Content-Type': 'text/html'});
98 res.write(content);
99 res.end();
100 });
95 } else { 101 } else {
96 onHeaders(res, () => { 102 onHeaders(res, () => {
97 const diff = process.hrtime(startTime); 103 const diff = process.hrtime(startTime);
......
...@@ -11,6 +11,13 @@ ...@@ -11,6 +11,13 @@
11 "charts" 11 "charts"
12 ], 12 ],
13 "author": "Rafal Wilinski raf.wilinski@gmail.com", 13 "author": "Rafal Wilinski raf.wilinski@gmail.com",
14 "contributors": [
15 {
16 "name": "Julien Breux",
17 "email": "julien.breux@gmail.com",
18 "url": "https://github.com/JulienBreux/"
19 }
20 ],
14 "license": "MIT", 21 "license": "MIT",
15 "dependencies": { 22 "dependencies": {
16 "on-headers": "^1.0.1", 23 "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!