UNPKG

3.86 kBMarkdownView Raw
1# express-status-monitor
2
3[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/express-status-monitor/Lobby/?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
4[![express-status-monitor on npm](https://img.shields.io/npm/v/express-status-monitor.svg)](https://www.npmjs.com/express-status-monitor)
5[![npm](https://img.shields.io/npm/dt/express-status-monitor.svg)](https://img.shields.io/npm/dt/express-status-monitor.svg)
6[![bitHound Overall Score](https://www.bithound.io/github/RafalWilinski/express-status-monitor/badges/score.svg)](https://www.bithound.io/github/RafalWilinski/express-status-monitor)
7[![CircleCI](https://img.shields.io/circleci/project/github/RafalWilinski/express-status-monitor/master.svg)](https://circleci.com/gh/RafalWilinski/express-status-monitor)
8
9Simple, self-hosted module based on Socket.io and Chart.js to report realtime server metrics for Express-based node servers.
10
11![Monitoring Page](http://i.imgur.com/AHizEWq.gif "Monitoring Page")
12
13## Demo
14
15[Demo available here](https://express-status-monitor-example-fjovaypblp.now.sh)
16
17## Support for other Node.js frameworks
18
19* [koa-monitor](https://github.com/capaj/koa-monitor) for Koa
20* [hapijs-status-monitor](https://github.com/ziyasal/hapijs-status-monitor) for hapi.js
21
22## Installation & setup
23
241. Run `npm install express-status-monitor --save`
252. Before any other middleware or router add following line:
26`app.use(require('express-status-monitor')());`
273. Run server and go to `/status`
28
29## Run examples
30
311. Go to `cd examples/`
322. Run `npm i`
333. Run server `npm start`
344. Go to `http://0.0.0.0:3000`
35
36## Options
37
38Monitor can be configured by passing options object into `expressMonitor` constructor.
39
40Default config:
41```javascript
42title: 'Express Status', // Default title
43path: '/status',
44websocket: existingSocketIoInstance,
45spans: [{
46 interval: 1, // Every second
47 retention: 60 // Keep 60 datapoints in memory
48}, {
49 interval: 5, // Every 5 seconds
50 retention: 60
51}, {
52 interval: 15, // Every 15 seconds
53 retention: 60
54}]
55
56```
57
58## Securing endpoint
59
60The HTML page handler is exposed as a `pageRoute` property on the main
61middleware function. So the middleware is mounted to intercept all requests
62while the HTML page handler will be authenticated.
63
64Example using https://www.npmjs.com/package/connect-ensure-login
65```javascript
66const ensureLoggedIn = require('connect-ensure-login').ensureLoggedIn()
67
68const statusMonitor = require('express-status-monitor')();
69app.use(statusMonitor);
70app.get('/status', ensureLoggedIn, statusMonitor.pageRoute)
71```
72
73Credits to [@mattiaerre](https://github.com/mattiaerre)
74
75Example using [http-auth](https://www.npmjs.com/package/http-auth)
76```javascript
77const auth = require('http-auth');
78const basic = auth.basic({realm: 'Monitor Area'}, function(user, pass, callback) {
79 callback(user === 'username' && pass === 'password');
80});
81
82// Set '' to config path to avoid middleware serving the html page (path must be a string not equal to the wanted route)
83const statusMonitor = require('express-status-monitor')({ path: '' });
84app.use(statusMonitor.middleware); // use the "middleware only" property to manage websockets
85app.get('/status', auth.connect(basic), statusMonitor.pageRoute); // use the pageRoute property to serve the dashboard html page
86```
87
88## Using module with socket.io in project
89
90If you're using socket.io in your project, this module could break your project because this module by default will spawn its own socket.io instance. To mitigate that, fill websocket parameter with your main socket.io instance as well as port parameter.
91
92## Tests and coverage
93
94In order to run test and coverage use the following npm commands:
95```
96npm test
97npm run coverage
98```
99
100## License
101
102[MIT License](https://opensource.org/licenses/MIT) © Rafal Wilinski