文档

5分钟快速入门

更新时间:

验证安装是否成功,需要确保which nodewhich agenthub的路径中包括.tnvm即可。

  • 阿里云账号,在这里 https://www.aliyun.com/product/nodejs 开通服务。

  • 一台可以连接到互联网的服务器,或者开发机器。

2. 操作指南

I. 创建应用

  • 登录阿里云官网 https://www.aliyun.com/。

  • 前往 Node.js性能平台控制台创建新应用 输入应用名 demo ,记录下 App IDApp Secret ,后面可以从应用界面的 设置 中查看该设置。

II. 服务器部署 Node.js 性能平台

a. 安装 Node.js 性能平台所需组件

# 安装版本管理工具 tnvm,安装过程出错参考:https://github.com/aliyun-node/tnvm
wget -O- https://raw.githubusercontent.com/aliyun-node/tnvm/master/install.sh | bash
# 如果遇到网络问题,请切换为如下命令:
# wget -O- https://code.aliyun.com/aliyun-node/tnvm/raw/master/install.sh | bash
source ~/.bashrc
# tnvm ls-remote alinode 查看需要的版本
tnvm install alinode-v3.11.4 # 安装需要的版本
tnvm use alinode-v3.11.4 # 使用需要的版本
npm install @alicloud/agenthub -g # 安装 agenthub
which node
/home/user/.tnvm/versions/alinode/v3.11.4/bin/node
which agenthub 
/home/user/.tnvm/versions/alinode/v3.11.4/bin/agenthub
                        

创建新应用中获得的App IDApp Secret 按如下所示保存为 yourconfig.json

{
  "appid": "12345",                          # 前面申请到的 appid,保存时删掉这条注释。
  "secret": "kflajglkajlgjalsgjlajdgfakjkgj" # 前面申请到的 secret,保存时删掉这条注释。
}

b. 启动 agenthub

agenthub start yourconfig.json
# 通过 agenthub list 查看 agenthub 是否启动成功
# 如果没有 agenthub 实例,通过调试模式启动 agenthub:
# DEBUG=* agenthub start yourconfig.json
# ~/.agenthub.log 查看 agenthub 日志。

c. 复制下面的代码到 demo.js

注意:该 demo 模拟计算密集型应用,请勿在生产环境中使用。

const http = require('http');
const crypto = require('crypto');
const reqHeaders = [];
const algorithm = 'aes-256-cbc';
const key = ['this', 'is', 'a', 'test'].join(' ');
const encode = function(str) {
  var buf = new Buffer(str)
  var encrypted = "";
  var cip = crypto.createCipher(algorithm, key);
  encrypted += cip.update(buf, 'binary', 'hex');
  encrypted += cip.final('hex');
  return encrypted;
};
const decode = function(encrypted){
  var decrypted = "";
  var decipher = crypto.createDecipher(algorithm, key);
  decrypted += decipher.update(encrypted, 'hex', 'binary');
  decrypted += decipher.final('binary');
  return decrypted;
}
http.createServer(function(req, res) {
  reqHeaders.push(req.headers);
  let enc = encode(req.headers['host']);
  let dec = decode(enc);
  res.end('hello')
}).listen(8848);

d. 启动应用

ENABLE_NODE_LOG=YES node demo.js

注意:

若出现提示信息 Environment variable <NODE_LOG_DIR> not configured, </tmp/> will be used to record node internal log.表明运行时日志(非应用日志)存储目录是默认的 /tmp/

III. 通过控制台观察监控数据,执行诊断操作

  • 控制台中观察各个监控信息。

  • Node.js进程数据中查看进程级别的数据。

注意:

1. 本例未配置 等功能。

2. 性能平台每分钟上传一次日志,请等待几分钟后查看数据。

3. 更详细的 Node.js 性能平台 runtime 部署参见 自助式部署 runtime

  • 本页导读 (0)
文档反馈