默认会自行创建 socket.io 实例,项目已用 socket.io 时需传入已有实例和端口,否则可能冲突;默认监控页路径为 /status,改 path 或设为空字符串会影响页面与中间件的挂载方式;需 Node 版本 > 4.x,且中间件要加在其他中间件和路由之前
express-status-monitor
RafalWilinskiMIT更新放缓给 Express 应用加一行中间件就能得到实时监控页面,查看 CPU、内存、响应时间和请求状态,类似 GitHub 状态页。
🚀 Realtime Monitoring solution for Node.js/Express.js apps, inspired by status.github.com, sponsored by https://dynobase.dev
npm install express-status-monitor --save
app.use(require('express-status-monitor')());README 未说明
给 Express 应用加一行中间件,就能在 /status 页面实时查看服务器指标
给 Express 应用加一行中间件就能得到实时监控页面,查看 CPU、内存、响应时间和请求状态,类似 GitHub 状态页。
核心能力
- 基于 Socket.io 和 Chart.js 实时推送指标
- 展示 CPU、内存、负载、事件循环、堆、响应时间、RPS 和状态码图表
- 支持配置多时间窗口采样间隔与内存保留点数
- 可配置健康检查,端点返回 200 即视为成功
- pageRoute 与 middleware 分离,便于接入登录或 Basic Auth 鉴权
容易踩的坑
- 1.1最新正式版2017-10-18 · 2017-10-18 17:09 UTC
Thanks to @colinrcummings there's an ability to hide selected charts 🙇
- 1.0.0Version 1.0!2017-07-29 · 2017-07-29 18:41 UTC
查看更新说明
After fixing some security issues and automating release process, we've decided to release new version using semantic versioning.
- 0.1.7Socket.io authorization2016-12-14 · 2016-12-14 16:43 UTC
查看更新说明
Thanks to @thom-nic socket.io connections are now authenticated.
- 0.1.3Status Codes chart2016-09-14 · 2016-09-14 21:15 UTC
查看更新说明
In this release we're proud to introduce you Status Codes chart and bring some fixes. In addition, example does contain
tester.jsscript which acts like benchmark but it's more like a tool for testing how does status works. - 0.1.2Add support for Node 4 back!pre-release2016-09-06 · 2016-09-06 06:49 UTC
查看更新说明
In this version @mattiaerre introduced new tests and brought back Node 4 support.
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
express-status-monitor
Simple, self-hosted module based on Socket.io and Chart.js to report realtime server metrics for Express-based node servers.

Demo
Support for other Node.js frameworks
- koa-monitor for Koa
- hapijs-status-monitor for hapi.js
Installation & setup
- Run
npm install express-status-monitor --save - Before any other middleware or router add following line:
app.use(require('express-status-monitor')()); - Run server and go to
/status
Note: This plugin works on Node versions > 4.x
Run examples
- Go to
cd examples/ - Run
npm i - Run server
npm start - 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
theme: 'default.css', // Default styles
path: '/status',
socketPath: '/socket.io', // In case you use a custom path
websocket: existingSocketIoInstance,
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
}],
chartVisibility: {
cpu: true,
mem: true,
load: true,
eventLoop: true,
heap: true,
responseTime: true,
rps: true,
statusCodes: true
},
healthChecks: [],
ignoreStartsWith: '/admin'
Health Checks
You can add a series of health checks to the configuration that will appear below the other stats. The health check will be considered successful if the endpoint returns a 200 status code.
// config
healthChecks: [{
protocol: 'http',
host: 'localhost',
path: '/admin/health/ex1',
port: '3000'
}, {
protocol: 'http',
host: 'localhost',
path: '/admin/health/ex2',
port: '3000'
}]

Securing endpoint
The HTML page handler is exposed as a pageRoute property on the main
middleware function. So the middleware is mounted to intercept all requests
while the HTML page handler will be authenticated.
Example using https://www.npmjs.com/package/connect-ensure-login
const ensureLoggedIn = require('connect-ensure-login').ensureLoggedIn()
const statusMonitor = require('express-status-monitor')();
app.use(statusMonitor);
app.get('/status', ensureLoggedIn, statusMonitor.pageRoute)
Credits to @mattiaerre
Example using http-auth
const auth = require('http-auth');
const basic = auth.basic({realm: 'Monitor Area'}, function(user, pass, callback) {
callback(user === 'username' && pass === 'password');
});
// Set '' to config path to avoid middleware serving the html page (path must be a string not equal to the wanted route)
const statusMonitor = require('express-status-monitor')({ path: '' });
app.use(statusMonitor.middleware); // use the "middleware only" property to manage websockets
app.get('/status', basic.check(statusMonitor.pageRoute)); // use the pageRoute property to serve the dashboard html page
Using module with socket.io in project
If 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.
Tests and coverage
In order to run test and coverage use the following npm commands:
npm test
npm run coverage