Merge pull request #25 from JulienBreux/feature/title-and-example
[Feature] Add title config and examples
Showing
6 changed files
with
73 additions
and
8 deletions
... | @@ -6,25 +6,33 @@ Simple, self-hosted module based on Socket.io and Chart.js to report realtime se | ... | @@ -6,25 +6,33 @@ Simple, self-hosted module based on Socket.io and Chart.js to report realtime se |
6 | 6 | ||
7 | ## Installation & setup | 7 | ## Installation & setup |
8 | 1. Run `npm install express-status-monitor --save` | 8 | 1. Run `npm install express-status-monitor --save` |
9 | 2. Before any other middleware or router add following line: | 9 | 2. Before any other middleware or router add following line: |
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 |
22 | retention: 60 // Keep 60 datapoints in memory | 30 | retention: 60 // Keep 60 datapoints in memory |
23 | }, { | 31 | }, { |
24 | interval: 5, // Every 5 seconds | 32 | interval: 5, // Every 5 seconds |
25 | retention: 60 | 33 | retention: 60 |
26 | }, { | 34 | }, { |
27 | interval: 15, // Every 15 seconds | 35 | interval: 15, // Every 15 seconds |
28 | retention: 60 | 36 | retention: 60 |
29 | }] | 37 | }] |
30 | 38 | ... | ... |
examples/index.js
0 → 100644
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 | }); |
examples/package.json
0 → 100644
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", | ... | ... |
-
Please register or sign in to post a comment