@achingbrain/appmetrics-dash 中文文档教程
Node Application Metrics Dashboard
节点应用程序指标仪表板 (appmetrics-dash) 提供了一个非常易于使用的基于 Web 的仪表板来显示正在运行的 Node.js 应用程序的性能指标。
如果您想将仪表板添加到您的应用程序创建的所有 HTTP 服务器,那么只需将:添加
// Before all other 'require' statements:
require('appmetrics-dash').attach();
到您的主 JavaScript 源文件的最顶部。
或者,要使用预加载:
$ node --require appmetrics-dash/attach app.js
或在 Node.js 8.0.0 和 6.12.0 以上版本中,使用 NODE_OPTIONS 环境变量:
$ export NODE_OPTIONS="--require appmetrics-dash/attach"
要将仪表板添加到一个特定的 HTTP 服务器,请使用:
var dash = require('appmetrics-dash');
// Other 'require' statements here
// Create HTTP server 'myHttpServer' here
dash.monitor({server: myHttpServer});
如果 服务器 然后使用:
// Before all other 'require' statements:
require('appmetrics-dash').monitor();
运行您的程序
$ node --require appmetrics-dash/monitor app.js
或使用或通过 NODE_OPTIONS 环境变量
$ export NODE_OPTIONS="--require appmetrics-dash/monitor"
:默认情况下,这会在端口 3001 上为仪表板创建一个新服务器。 路径默认为 /appmetrics-dash
。 例如 http://localhost:3001/appmetrics-dash
仪表盘上可用的数据如下:
- CPU Profiling (via a separate tab)
- HTTP Incoming Requests
- HTTP Throughput
- Average Reponse Times (top 5)
- CPU
- Memory
- Heap
- Event Loop Times
- Environment
- Other Requests
- HTTP Outbound Requests
除了显示数据,它还提供生成两者的能力 Node Report 和 Heap Snapshots 直接来自仪表板。 节点报告将显示在浏览器的新选项卡中,而堆快照将写入磁盘以加载到 Chrome DevTools 进行分析。 这些都可以从屏幕左上角的选项菜单中触发
仪表板使用 Node Application Metrics 监控应用程序。
Installation
npm install appmetrics-dash
Performance overhead
我们的测试表明,处理方面的性能开销很小,应用程序的 CPU 使用率增加不到 0.5%。 需要大约 30 MB 的额外内存来收集有关您的系统和应用程序的信息,然后这些信息会在仪表板中可视化。
我们通过监控示例应用程序 Acme Air 收集了这些信息。 我们使用 MongoDB 作为我们的数据存储,并使用 JMeter 通过程序驱动负载。 我们使用 Node.js 版本 6.10.3 执行此测试
API Documentation
attach(options)
- options {Object} Options are the same as for
dash.monitor()
.
自动附加到此调用后创建的所有 http
服务器,为每个服务器调用 dash.monitor(options)
。
使用附加的简单示例
var dash = require('appmetrics-dash');
dash.attach();
var http = require('http');
const port = 3000;
const requestHandler = (request, response) => {
response.end('Hello')
}
const server = http.createServer(requestHandler);
server.listen(port, (err) => {
if (err) {
return console.log('An error occurred', err)
}
console.log(`Server is listening on ${port}`)
});
monitor(options)
- options.url {String} Path to serve dashboard from. Optional, defaults to
'/appmetrics-dash'
. - options.console {Object} Some messages are printed to the console using
console.log()
andconsole.error()
. Optional, defaults to the globalconsole
object. - options.server {Object} An instance of a node
http
server to serve the dashboard from. Optional, default is to create a server (seeport
andhost
). - options.port {String|Number} Port to listen on if creating a server. Optional, unused if
server
option is used. - options.host {String} Host to listen on if creating a server. Optional, unused if
server
option is used. - options.appmetrics {Object} An instance of
require('appmetrics')
can be injected if the application wants to use appmetrics, since it is a singleton module and only one can be present in an application. Optional, defaults to the appmetrics dependency of this module. - options.nodereport {Object} An instance of
require('node-report')
can be injected if the application wants to use node-report, since it is a singleton module and only one can be present in an application. Optional, defaults to the node-report dependency of this module. The ability to generate reports can be disabled by setting this tonull
orundefined
. - options.title {String} Title for the dashboard.
- options.docs {String} URL link to accompanying documentation.
- options.middleware {Object} Pass in middleware function to be used by server.
Contributing
我们欢迎贡献。 有关贡献者许可协议和其他信息的详细信息,请参阅 CONTRIBUTING.md。 如果你想做任何比修复错误或小改进更复杂的事情,那么我们建议在做工作之前先在一个问题中讨论它,以确保它可能被接受。 我们也热衷于提高测试覆盖率,除非有附带测试,否则可能不会接受新代码。
Module Long Term Support Policy
此模块采用模块长期支持 (LTS) 政策,具有以下生命周期终止 (EOL) 日期:
Module Version | Release Date | Minimum EOL | EOL With | Status |
---|---|---|---|---|
V4.x.x | Jun 2018 | Dec 2019 | Current |
License
节点应用程序指标Dashboard 使用 Apache v2.0 许可证获得许可。
Node Application Metrics Dashboard
Node Application Metrics Dashboard (appmetrics-dash) provides a very easy-to-use web based dashboard to show the performance metrics of your running Node.js application.
If you want to add the dashboard to all HTTP servers created by your application then simply add:
// Before all other 'require' statements:
require('appmetrics-dash').attach();
to the very top of your main JavaScript source file.
Alternatively, to use preloading:
$ node --require appmetrics-dash/attach app.js
or in Node.js from versions 8.0.0 and 6.12.0 onwards, use the NODE_OPTIONS environment variable:
$ export NODE_OPTIONS="--require appmetrics-dash/attach"
If you want to add the dashboard to one specific HTTP server then use:
var dash = require('appmetrics-dash');
// Other 'require' statements here
// Create HTTP server 'myHttpServer' here
dash.monitor({server: myHttpServer});
If you are not creating an HTTP server then use:
// Before all other 'require' statements:
require('appmetrics-dash').monitor();
or run your program with
$ node --require appmetrics-dash/monitor app.js
or via the NODE_OPTIONS environment variable:
$ export NODE_OPTIONS="--require appmetrics-dash/monitor"
This creates a new server for the dashboard on port 3001 by default. The path defaults to /appmetrics-dash
. E.g. http://localhost:3001/appmetrics-dash
The data available on the dashboard is as follows:
- CPU Profiling (via a separate tab)
- HTTP Incoming Requests
- HTTP Throughput
- Average Reponse Times (top 5)
- CPU
- Memory
- Heap
- Event Loop Times
- Environment
- Other Requests
- HTTP Outbound Requests
As well as displaying data, it also provides the ability to generate both Node Report and Heap Snapshots directly from the dashboard. The Node Report will display in a new tab in the browser whilst the Heap Snapshot will be written to disk for loading into the Chrome DevTools for analysis. These can both be triggered from the options menu in the top left of the screen
The dashboard uses Node Application Metrics to monitor the application.
Installation
npm install appmetrics-dash
Performance overhead
Our testing has shown that the performance overhead in terms of processing is minimal, adding less than 0.5 % to the CPU usage of your application. The additional memory required is around 30 MB to gather information about your system and application which is then visualized in the dashboard.
We gathered this information by monitoring the sample application Acme Air. We used MongoDB as our datastore and used JMeter to drive load though the program. We have performed this testing with Node.js version 6.10.3
API Documentation
attach(options)
- options {Object} Options are the same as for
dash.monitor()
.
Auto-attach to all http
servers created after this call, calling dash.monitor(options)
for every server.
Simple example using attach
var dash = require('appmetrics-dash');
dash.attach();
var http = require('http');
const port = 3000;
const requestHandler = (request, response) => {
response.end('Hello')
}
const server = http.createServer(requestHandler);
server.listen(port, (err) => {
if (err) {
return console.log('An error occurred', err)
}
console.log(`Server is listening on ${port}`)
});
monitor(options)
- options.url {String} Path to serve dashboard from. Optional, defaults to
'/appmetrics-dash'
. - options.console {Object} Some messages are printed to the console using
console.log()
andconsole.error()
. Optional, defaults to the globalconsole
object. - options.server {Object} An instance of a node
http
server to serve the dashboard from. Optional, default is to create a server (seeport
andhost
). - options.port {String|Number} Port to listen on if creating a server. Optional, unused if
server
option is used. - options.host {String} Host to listen on if creating a server. Optional, unused if
server
option is used. - options.appmetrics {Object} An instance of
require('appmetrics')
can be injected if the application wants to use appmetrics, since it is a singleton module and only one can be present in an application. Optional, defaults to the appmetrics dependency of this module. - options.nodereport {Object} An instance of
require('node-report')
can be injected if the application wants to use node-report, since it is a singleton module and only one can be present in an application. Optional, defaults to the node-report dependency of this module. The ability to generate reports can be disabled by setting this tonull
orundefined
. - options.title {String} Title for the dashboard.
- options.docs {String} URL link to accompanying documentation.
- options.middleware {Object} Pass in middleware function to be used by server.
Contributing
We welcome contributions. Please see CONTRIBUTING.md for details about the contributor licence agreement and other information. If you want to do anything more involved than a bug fix or a minor enhancement then we would recommend discussing it in an issue first before doing the work to make sure that it's likely to be accepted. We're also keen to improve test coverage and may not accept new code unless there are accompanying tests.
Module Long Term Support Policy
This module adopts the Module Long Term Support (LTS) policy, with the following End Of Life (EOL) dates:
Module Version | Release Date | Minimum EOL | EOL With | Status |
---|---|---|---|---|
V4.x.x | Jun 2018 | Dec 2019 | Current |
License
The Node Application Metrics Dashboard is licensed using an Apache v2.0 License.