5-minute quick start

更新时间:
复制 MD 格式

To verify the installation, ensure that the paths for which node and which agenthub include .tnvm.

  • An Alibaba Cloud account. You can activate the service at https://www.aliyun.com/product/nodejs.

  • A server or developer machine that can connect to the Internet.

2. User guide

I. Create an application

  • Log in to the Alibaba Cloud website at https://www.aliyun.com/.

  • Go to the Node.js Performance Platform console. Click Create New Application. Enter demo as the application name and record the App ID and App Secret. You can view this information later in Settings on the application page.

II. Deploy Node.js Performance Platform on a server

a. Install required components for Node.js Performance Platform

# Install the tnvm version management tool. If an error occurs during installation, see https://github.com/aliyun-node/tnvm
wget -O- https://raw.githubusercontent.com/aliyun-node/tnvm/master/install.sh | bash
# If you encounter network issues, switch to the following command:
# wget -O- https://code.aliyun.com/aliyun-node/tnvm/raw/master/install.sh | bash
source ~/.bashrc
# Run tnvm ls-remote alinode to view available versions
tnvm install alinode-v3.11.4 # Install the required version
tnvm use alinode-v3.11.4 # Use the required version
npm install @alicloud/agenthub -g # Install 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
                        

Save the App ID and App Secret to a file named yourconfig.json in the following format.

{
  "appid": "12345",                          # The appid you obtained earlier. Remove this comment when you save the file.
  "secret": "kflajglkajlgjalsgjlajdgfakjkgj" # The secret you obtained earlier. Remove this comment when you save the file.
}

b. Start agenthub

agenthub start yourconfig.json
# Run agenthub list to check if agenthub started successfully.
# If no agenthub instance exists, start agenthub in debug mode:
# DEBUG=* agenthub start yourconfig.json
# Check the agenthub log at ~/.agenthub.log.

c. Copy the following code to demo.js

Note: This demo simulates a compute-intensive application. Do not use it in a production environment.

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. Start the application

ENABLE_NODE_LOG=YES node demo.js

Note:

If the message Environment variable <NODE_LOG_DIR> not configured, </tmp/> will be used to record node internal log. appears, it means that the runtime logs (not application logs) are stored in the /tmp/ directory by default.

III. Monitor data and perform diagnostics in the console

  • Monitor the metrics in the console.

  • View process-level data in Node.js Process Data.

Note:

1. This example is not configured with other features.

2. The performance platform uploads logs once per minute. It may take a few minutes for the data to appear.

3. For more information about Node.js Performance Platform runtime deployment, see Self-service runtime deployment.