5分鐘快速入門
更新時間:
驗證安裝是否成功,需要確保which node
和which agenthub
的路徑中包括.tnvm
即可。
阿里云賬號,在這里 https://www.aliyun.com/product/nodejs 開通服務。
一臺可以連接到互聯(lián)網(wǎng)的服務器,或者開發(fā)機器。
2. 操作指南
I. 創(chuàng)建應用
登錄阿里云官網(wǎng) https://www.aliyun.com/。
前往 Node.js性能平臺控制臺
創(chuàng)建新應用
輸入應用名demo
,記錄下App ID
和App 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
# 如果遇到網(wǎng)絡問題,請切換為如下命令:
# 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
將創(chuàng)建新應用
中獲得的App ID
和 App 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 模擬計算密集型應用,請勿在生產(chǎn)環(huán)境中使用。
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
注意:
若出現(xiàn)提示信息 Environment variable <NODE_LOG_DIR> not configured, </tmp/> will be used to record node internal log.
表明運行時日志(非應用日志)存儲目錄是默認的 /tmp/
。
III. 通過控制臺觀察監(jiān)控數(shù)據(jù),執(zhí)行診斷操作
在 控制臺中觀察各個監(jiān)控信息。
Node.js進程數(shù)據(jù)
中查看進程級別的數(shù)據(jù)。
注意:
1. 本例未配置 、 等功能。
2. 性能平臺每分鐘上傳一次日志,請等待幾分鐘后查看數(shù)據(jù)。
3. 更詳細的 Node.js 性能平臺 runtime 部署參見 自助式部署 runtime。
文檔內容是否對您有幫助?