apm-nodejs-agent

1.0.99 • Public • Published

NodejsAgent

APM的nodejs探针,通过实时采集接口调用、外部调用以及各种中间件的指标、调用链数据,帮助用户全面掌握 nodejs 应用的运行情况,快速定位线上故障的根源。

无修改接入

npm install -S apm-nodejs-agent && APM_APP_NAME=apm-nodejs-demo APM_AK=* APM_SK=* APM_MASTER_ADDRESS=* node -r apm-nodejs-agent/tracing app.js

自定义接入

  1. 安装依赖包
npm install -S apm-nodejs-agent
  1. 启动文件中增加代码
const process = require('process');
const agent = require('apm-nodejs-agent');

agent.start({
  appName: 'apm-nodejs-demo',
  masterAddress: '*',
  AK: '*',
  SK: '*'
}).then(()=>{
  console.log('Agent trace start');
}).catch((error)=>{
  console.log('Error agent trace',error);
})

process.on('SIGTERM',()=>{
  agent.stop();
})

使用说明

推荐node版本V14版本以上。
支持node版本v10版本以上。

参数说明

const agentDefaultConfig = {
  AK: '', // 必传字段
  SK: '', // 必传字段
  appName: '', // 必传字段
  masterAddress: '',// 必传字段
  business: '', // 不传是default
  subBusiness: '', // 多层子应用使用/分割
  env: '',
  envTag: '',
  instanceName: '',
  accessAddress:'', // 如果传递上报地址就用这个,不用masterAddress返回的地址
  appType: 'NODEJS',
  agentVersion: '1.0.0', // 版本
  logOut: 'file', // file文件或者console控制台
  logFilePath:'', // 默认放在~/apm/instances/{appName}-{instanceName}/logs/
  logFileName: 'apm.log', // 日志文件名
  logLevel: 'info', // 日志等级
  maxLogSize: 10 * 1024 * 1024, // 日志文件大小,字节
  logBackups: 4, // 日志循环覆盖个数
  registerUrl: '/apm2/master/v1/register', // 注册地址
  heartbeatUrl: '/apm2/master/v1/heartbeat', // 心跳地址
  heartBeatInterval: 60 * 1000, // 心跳间隔,毫秒
  metricInterval: 60*1000, // 指标间隔,毫秒
  maxMessageSize: 1000000, // webscoket,最大数据大小
  maxGlobalPathLength: 1000, // 最大GlobalPath的长度
  maxSpanLength: 200, // 最大span数
  maxEventLength: 200, // 最大event数
  debug: false, // 是否调试状态
  active: true,
  disablePlugins:'', // 禁用的组件,组件包括axios,egg,express,http-client,http-server,ioredis,koa,mongodb,mysql,redis多个禁用,分隔
};

组件维护者

zhangjie230@huawei.com
panjing25@huawei.com

支持插件

  • express >=4.0.0
  • koa >=2.0.0
  • mysql >=2.18.1
  • mysql2 >=2.3.3
  • ioredis >=2.0.0
  • http >=12.17
  • https >=12.17
  • axios >=0.26.0
  • request >=2.88.2
  • request-promise >=4.2.6

目录

src 源代码
./metric 指标数据
./plugins 拦截插件
./process 心跳,指标,调用链处理
./trace 调用链
./utils 方法集合
./agent.js 入口文件
./config.js 配置文件
test 单元测试
index.js 入口文件
tracing.js 无感知引入文件

DEV

npm install

TEST

整体 test,需要在配置文件/test/test.js
npm run test 调试 test,断点调试
mocha test.js

changelog

  • 1.0.99 修复axios拦截bug

  • 1.0.92 删除敏感词

Readme

Keywords

Package Sidebar

Install

npm i apm-nodejs-agent

Weekly Downloads

2,427

Version

1.0.99

License

MIT

Unpacked Size

200 kB

Total Files

76

Last publish

Collaborators

  • to16