88
99Easy-Monitor v3.0 Node.js Runtime 插件,输出性能日志,并且可以进行实时的运行时状态采样。
1010
11- 点击访问 [ 控制台 Demo] ( http://www.devtoolx.com/easy-monitor )  进行体验,完整的性能监控部署文档:https://www.yuque.com/hyj1991/easy-monitor 
11+ 点击访问 [ 控制台 Demo] ( http://www.devtoolx.com/easy-monitor )  进行体验,完整的性能监控部署文档:< https://www.yuque.com/hyj1991/easy-monitor > 
1212
1313## 兼容性  
1414
@@ -18,24 +18,16 @@ xprofiler 插件支持三大主流操作系统:
1818-  Linux (x64 / arm64)
1919-  macosX (x64 / arm64)
2020
21- 支持的 node .js runtime 版本:
21+ 支持的 Node .js runtime 版本:
2222
23- -  v12.x
24- -  v13.x
25- -  v14.x
26- -  v15.x
27- -  v16.x
28- -  v17.x
2923-  v18.x
30- -  v19.x
3124-  v20.x
32- -  v21.x
3325-  v22.x
3426
35- 更低的版本因为在此项目创建时已经不在官方 LTS 计划中,故正常情况下不再支持。
36- 
37- 需要在 ` node-v12.x `  以下的版本中使用,可以使用 ` v1.x-staging `  分支的的最新版本:[ 1.4.0] ( https://github.com/X-Profiler/xprofiler/tree/v1.x-staging ) 
27+ 更低的版本已经不在 Node.js 官方 LTS 计划中,故正常情况下不再支持。
3828
29+ -  需要在 ` node-v16.x `  以下的版本中使用,可以使用 ` 2.x `  分支的的最新版本:< https://github.com/X-Profiler/xprofiler/tree/2.x > 
30+ -  需要在 ` node-v12.x `  以下的版本中使用,可以使用 ` 1.x `  分支的的最新版本:[ 1.4.0] ( https://github.com/X-Profiler/xprofiler/tree/v1.x-staging ) 
3931
4032## 快速开始  
4133
@@ -47,10 +39,10 @@ xprofiler 插件支持三大主流操作系统:
4739npm i xprofiler --save --xprofiler_binary_host_mirror=https://npmmirror.com/mirrors/xprofiler
4840``` 
4941
50- 如果 npmmirror 镜像暂时没同步的话,也可以执行阿里云镜像 :
42+ 如果 npmmirror 镜像暂时没同步的话,也可以从 GitHub Releases 下载 :
5143
5244``` bash 
53- npm i xprofiler --save --xprofiler_binary_host_mirror=http://devtoolx.com/xprofiler 
45+ npm i xprofiler --save
5446``` 
5547
5648>  这里使用了 ` @mapbox/node-pre-gyp `  帮助开发者无需进行本地编译即可使用此插件,默认插件位于 [ Github Release] ( https://github.com/X-Profiler/xprofiler/releases )  页面,国内访问可能较慢,你也可以自行镜像到其它位置加速安装。
@@ -74,45 +66,41 @@ require('xprofiler')();
7466
7567本插件提供方以下的可配置参数:
7668
77- *  ** log_dir** : 内核输出日志和性能文件的目录,默认为 ` os.tmpdir() ` 
78- *  ** log_interval** : 内核对性能日志采样的时间间隔,默认为 ` 60s ` 
79- *  ** log_level** : 输出日志信息级别,0 info,1 error,2 debug,默认只输出 info 和 error 日志,默认为 ` 1 ` 
80- *  ** log_type** : 日志输出位置,0 文件,1 控制台,默认为 ` 0 ` 
81- *  ** log_format_alinode** : 是否以 Node.js 性能平台(原 AliNode)的格式输出性能分析日志,默认为 ` false ` 
82- *  ** patch_http** : 是否对原生 http 模块进行 patch,输出 http 请求相关信息,默认 ` true ` 
83- *  ** patch_http_with_diagnostics_channel** : 是否对通过 diagnostics_channel 模块进行 patch,输出 http 请求相关信息,在 esm 下需要开启,默认 ` false ` 
84- *  ** patch_http_timeout** : 默认 http 请求超时时间,单位秒,作为 http 请求统计,默认 ` 30 ` 
85- *  ** check_throw** : ` xprofiler `  启动时检测错误时是否需要 throw,默认 ` true ` 
86- *  ** auto_incr_heap_limit_size** : ` enable_auto_incr_heap_limit `  开启后,每次自动增加的堆上限大小,默认为 ` 256 `  (MB)
87- *  ** enable_log_uv_handles** : 是否要采集 libuv 句柄的详细分类信息,比如 tcp 句柄数量,timers 数量,文件句柄数量等,默认为 ` true ` 
88- *  ** enable_fatal_error_hook** : 是否需要在 V8 出现 FatalError 时配置钩子,默认 ` true ` 
89- *  ** enable_fatal_error_report** : 是否需要在 V8 出现 FataLError 时导出 Report 文件,默认 ` true ` 
90- *  ** enable_fatal_error_coredump** : 是否需要在 V8 出现 FataLError 时 Coredump,默认 ` false ` 
91- *  ** enable_http_profiling** : 是否需要 CPU 采样时进行 HTTP Profiling。默认 ` false ` 
92- *  ** enable_auto_incr_heap_limit** : 是否需要在 Node.js 进程达到堆上限时自动增加堆上限防止 OOM,默认 ` false ` 
93- 
69+ -  ** log_dir** : 内核输出日志和性能文件的目录,默认为 ` os.tmpdir() ` 
70+ -  ** log_interval** : 内核对性能日志采样的时间间隔,默认为 ` 60s ` 
71+ -  ** log_level** : 输出日志信息级别,0 info,1 error,2 debug,默认只输出 info 和 error 日志,默认为 ` 1 ` 
72+ -  ** log_type** : 日志输出位置,0 文件,1 控制台,默认为 ` 0 ` 
73+ -  ** log_format_alinode** : 是否以 Node.js 性能平台(原 AliNode)的格式输出性能分析日志,默认为 ` false ` 
74+ -  ** patch_http** : 是否对原生 http 模块进行 patch,输出 http 请求相关信息,默认 ` true ` 
75+ -  ** patch_http_timeout** : 默认 http 请求超时时间,单位秒,作为 http 请求统计,默认 ` 30 ` 
76+ -  ** check_throw** : ` xprofiler `  启动时检测错误时是否需要 throw,默认 ` true ` 
77+ -  ** auto_incr_heap_limit_size** : ` enable_auto_incr_heap_limit `  开启后,每次自动增加的堆上限大小,默认为 ` 256 `  (MB)
78+ -  ** enable_log_uv_handles** : 是否要采集 libuv 句柄的详细分类信息,比如 tcp 句柄数量,timers 数量,文件句柄数量等,默认为 ` true ` 
79+ -  ** enable_fatal_error_hook** : 是否需要在 V8 出现 FatalError 时配置钩子,默认 ` true ` 
80+ -  ** enable_fatal_error_report** : 是否需要在 V8 出现 FataLError 时导出 Report 文件,默认 ` true ` 
81+ -  ** enable_fatal_error_coredump** : 是否需要在 V8 出现 FataLError 时 Coredump,默认 ` false ` 
82+ -  ** enable_http_profiling** : 是否需要 CPU 采样时进行 HTTP Profiling。默认 ` false ` 
83+ -  ** enable_auto_incr_heap_limit** : 是否需要在 Node.js 进程达到堆上限时自动增加堆上限防止 OOM,默认 ` false ` 
9484
9585您可以通过环境变量或者在 JavaScript 代码中引入插件时传入配置的方式来使用这些配置,具体如下所示:
9686
9787#### 1. 环境变量配置  
9888
99- *  ** XPROFILER_LOG_DIR** : 其值为 String,覆盖 ` log_dir ` 
100- *  ** XPROFILER_LOG_INTERVAL** : 其值为 Number,覆盖 ` log_interval ` 
101- *  ** XPROFILER_LOG_LEVEL** : 其值为 String,覆盖 ` log_level ` 
102- *  ** XPROFILER_LOG_TYPE** : 其值为 String,覆盖 ` log_type ` 
103- *  ** XPROFILER_LOG_FORMAT_ALINODE** : 其值为 YES/NO,覆盖 ` log_format_alinode ` 
104- *  ** XPROFILER_PATCH_HTTP** : 其值为 YES/NO,覆盖 ` patch_http ` 
105- *  ** XPROFILER_PATCH_HTTP_WITH_DIAGNOSTICS_CHANNEL** : 其值为 YES/NO,覆盖 ` patch_http_with_diagnostics_channel ` 
106- *  ** XPROFILER_PATCH_HTTP_TIMEOUT** : 其值为 String,覆盖 ` patch_http_timeout ` 
107- *  ** XPROFILER_CHECK_THROW** : 其值为 YES/NO 覆盖 ` check_throw ` 
108- *  ** XPROFILER_AUTO_INCR_HEAP_LIMIT_SIZE** : 其值为 String 覆盖 ` auto_incr_heap_limit_size ` 
109- *  ** XPROFILER_ENABLE_LOG_UV_HANDLES** : 其值为 YES/NO,覆盖 ` enable_log_uv_handles ` 
110- *  ** XPROFILER_ENABLE_FATAL_ERROR_HOOK** : 其值为 YES/NO,覆盖 ` enable_fatal_error_hook ` 
111- *  ** XPROFILER_ENABLE_FATAL_ERROR_REPORT** : 其值为 YES/NO,覆盖 ` enable_fatal_error_report ` 
112- *  ** XPROFILER_ENABLE_FATAL_ERROR_COREDUMP** : 其值为 YES/NO,覆盖 ` enable_fatal_error_coredump ` 
113- *  ** XPROFILER_ENABLE_HTTP_PROFILING** : 其值为 YES/NO,覆盖 ` enable_http_profiling ` 
114- *  ** XPROFILER_ENABLE_AUTO_INCR_HEAP_LIMIT** : 其值为 YES/NO 覆盖 ` enable_auto_incr_heap_limit ` 
115- 
89+ -  ** XPROFILER_LOG_DIR** : 其值为 String,覆盖 ` log_dir ` 
90+ -  ** XPROFILER_LOG_INTERVAL** : 其值为 Number,覆盖 ` log_interval ` 
91+ -  ** XPROFILER_LOG_LEVEL** : 其值为 String,覆盖 ` log_level ` 
92+ -  ** XPROFILER_LOG_TYPE** : 其值为 String,覆盖 ` log_type ` 
93+ -  ** XPROFILER_LOG_FORMAT_ALINODE** : 其值为 YES/NO,覆盖 ` log_format_alinode ` 
94+ -  ** XPROFILER_PATCH_HTTP** : 其值为 YES/NO,覆盖 ` patch_http ` 
95+ -  ** XPROFILER_PATCH_HTTP_TIMEOUT** : 其值为 String,覆盖 ` patch_http_timeout ` 
96+ -  ** XPROFILER_CHECK_THROW** : 其值为 YES/NO 覆盖 ` check_throw ` 
97+ -  ** XPROFILER_AUTO_INCR_HEAP_LIMIT_SIZE** : 其值为 String 覆盖 ` auto_incr_heap_limit_size ` 
98+ -  ** XPROFILER_ENABLE_LOG_UV_HANDLES** : 其值为 YES/NO,覆盖 ` enable_log_uv_handles ` 
99+ -  ** XPROFILER_ENABLE_FATAL_ERROR_HOOK** : 其值为 YES/NO,覆盖 ` enable_fatal_error_hook ` 
100+ -  ** XPROFILER_ENABLE_FATAL_ERROR_REPORT** : 其值为 YES/NO,覆盖 ` enable_fatal_error_report ` 
101+ -  ** XPROFILER_ENABLE_FATAL_ERROR_COREDUMP** : 其值为 YES/NO,覆盖 ` enable_fatal_error_coredump ` 
102+ -  ** XPROFILER_ENABLE_HTTP_PROFILING** : 其值为 YES/NO,覆盖 ` enable_http_profiling ` 
103+ -  ** XPROFILER_ENABLE_AUTO_INCR_HEAP_LIMIT** : 其值为 YES/NO 覆盖 ` enable_auto_incr_heap_limit ` 
116104
117105#### 2. 引入插件时传入配置  
118106
@@ -140,7 +128,6 @@ const defaultConfig = {
140128  log_type:  0 ,
141129  log_format_alinode:  false ,
142130  patch_http:  true ,
143-   patch_http_with_diagnostics_channel:  false ,
144131  patch_http_timeout:  30 , //  seconds,
145132  check_throw:  true ,
146133  auto_incr_heap_limit_size:  128  //  MB,
@@ -161,14 +148,14 @@ const xprofilerConfig = Object.assign({}, defaultConfig, envConfig, userConfig);
161148
162149本插件按照固定的格式来输出性能分析日志,但是也目前为了兼容已有的 alinode 运行时日志,提供了对 alinode 的支持,通过 ` log_format_alinode: true `  配置或者 ` XPROFILER_LOG_FORMAT_ALINODE=YES `  环境变量来启用 alinode 日志。两种日志文件名区别如下:
163150
164- *  默认 xprofiler 日志文件名称
165-   *  info 日志:xprofiler-${YYYYMMDD}.log
166-   *  error 日志:xprofiler-error-${YYYYMMDD}.log
167-   *  debug 日志:xprofiler-debug-${YYYYMMDD}.log
168- *  以 alinode 方式输出日志文件名称
169-   *  info 日志:node-${YYYYMMDD}.log
170-   *  error 日志:node-error-${YYYYMMDD}.log
171-   *  debug 日志:node-debug-${YYYYMMDD}.log
151+ -  默认 xprofiler 日志文件名称
152+   -  info 日志:xprofiler-${YYYYMMDD}.log
153+   -  error 日志:xprofiler-error-${YYYYMMDD}.log
154+   -  debug 日志:xprofiler-debug-${YYYYMMDD}.log
155+ -  以 alinode 方式输出日志文件名称
156+   -  info 日志:node-${YYYYMMDD}.log
157+   -  error 日志:node-error-${YYYYMMDD}.log
158+   -  debug 日志:node-debug-${YYYYMMDD}.log
172159
173160默认的 xprofiler 和 alinode 两种日志的主要区别在日志前缀上(当然输出的部分内容也不尽相同),其中 xprofiler 日志前缀如下:
174161
@@ -231,16 +218,14 @@ xprofctl <action> -p <pid> [-w <thread_id>] [-t profiling_time]
231218copyright 2019
232219``` 
233220
234- 
235221## 插件架构和实现原理  
236222
237223参见 [ 文档 - 整体架构] ( https://www.yuque.com/hyj1991/easy-monitor/architecture ) 
238224
239- 
240225## 稳定性  
241226
242- xprofiler 每个 commit 都会通过 github actions 进行在 windows/linux/macos 下的编译以及单元测试,如果您在使用中依旧出现意外的 crash,可以反馈到  [ Issue 列表 ] ( https://github.com/X-Profiler/xprofiler/issues )  进行跟踪处理。 
243- 
227+ xprofiler 每个 commit 都会通过 github actions 进行在 windows/linux/macos 下的编译以及单元测试,
228+ 如果您在使用中依旧出现意外的 crash,可以反馈到  [ Issue 列表 ] ( https://github.com/X-Profiler/xprofiler/issues )  进行跟踪处理。 
244229
245230## 测试与代码覆盖率  
246231
@@ -252,19 +237,17 @@ npm run cov
252237
253238master 分支的代码覆盖率情况可以参见 [ codecov badge] ( https://codecov.io/gh/X-Profiler/xprofiler/branch/master ) 。
254239
255- 
256240## 如何参与贡献  
257241
258- *  fork 本仓库至你自己的 github 仓库列表中
259- *  clone 你 fork 出来的仓库至本地开发
260- *  进行本地开发,添加功能或者修改 bug,并且附上必要的测试
261- *  请在 commit 中描述下添加的功能或者修改 bug 的详细信息,并提交至你的远程仓库
262- *  在 [ PR] ( https://github.com/X-Profiler/xprofiler/pulls )  页面选择 New Pull Request,继续选择 compare across forks,在列表中选中你的 Fork,然后创建新的 PR
263- *  查看 pr 下的 travis/appveypr  CI 状态,如果执行失败请到对应页面查看失败原因并在你自己的仓库下进行修复,修复 commit 会自动同步到此 pr 下,无需关闭重启发起
242+ -  fork 本仓库至你自己的 github 仓库列表中
243+ -  clone 你 fork 出来的仓库至本地开发
244+ -  进行本地开发,添加功能或者修改 bug,并且附上必要的测试
245+ -  请在 commit 中描述下添加的功能或者修改 bug 的详细信息,并提交至你的远程仓库
246+ -  在 [ PR] ( https://github.com/X-Profiler/xprofiler/pulls )  页面选择 New Pull Request,继续选择 compare across forks,在列表中选中你的 Fork,然后创建新的 PR
247+ -  查看 pr 下的 GitHub Action  CI 状态,如果执行失败请到对应页面查看失败原因并在你自己的仓库下进行修复,修复 commit 会自动同步到此 pr 下,无需关闭重启发起
264248
265249我们将在 review 后选择合并至本仓库内,贡献者也会加入到本项目的协作者列表中。
266250
267- 
268251## 贡献者  
269252
270253[ ![ contributors] ( https://contrib.rocks/image?repo=x-profiler/xprofiler&max=240&columns=26 )] ( https://github.com/x-profiler/xprofiler/graphs/contributors ) 
0 commit comments