Deploy a self-managed runtime
Node.js Performance Platform uses tnvm to manage runtime versions. To install tnvm, run the following command.
wget -O- https://raw.githubusercontent.com/aliyun-node/tnvm/master/install.sh | bashThe installation script prompts you to add tnvm to your system commands. Follow the instructions for your operating system. For example, on Linux:
source ~/.bashrcUse tnvm to install the required runtime. For more information about available versions, see Node.js Performance Platform runtime versions.
Run the following command to view remote versions.
tnvm ls-remote alinodeInstall the required version. For more information, see Version mapping.
Select an alinode version that matches the Node.js version of your application.
tnvm install alinode-vx.y.zRun the following command to use the vx.y.z runtime.
tnvm use alinode-vx.y.z2. Install agenthub
Agenthub is the resident proxy service for Node.js Performance Platform. It is used to run monitoring and diagnostic operations and provides a set of commands that the Node.js Performance Platform service requires to run tasks. The Node.js Performance Platform service only has permission to run these commands.
Agenthub is also an npm command line interface. To install it, run the following command:
npm install @alicloud/agenthub -gFor Alibaba Cloud users, use cnpm to install any npm module.
3. Configure and start agenthub
Agenthub requires a configuration file. Agenthub only runs commands or reads logs in the folders specified in the configuration file.
Minimal configuration
The minimal configuration requires only an App ID and a secret, in the following format:
{
"appid": "<yourAPPID>",
"secret": "<yourSecret>"
}You can find your App ID and App Secret on the Application Settings page. Save this configuration as config.json. Then, run the following command:
$ agenthub start config.jsonAgenthub runs as a resident process. The agenthub log file is located at ~/.agenthub.log. If agenthub fails to start, the console does not display system and process details. To diagnose the issue, you can start agenthub in DEBUG mode and check the ~/.agenthub.log file.
DEBUG=* agenthub start config.jsonAfter deployment, navigate to https://node.console.aliyun.com/ to view your application details. If the deployment is successful, your application performance data appears in about one minute.
Detailed configuration
The detailed configuration is as follows:
Note: The value of logdir must match the value of the NODE_LOG_DIR environment variable that is set when you start the application.
{
"appid": "<yourAPPID>",
"secret": "<yourSecret>",
"logdir": "</path/to/your/log/dir>",
"error_log": [
"</path/to/your/error.log>",
"Path to your application's business-level error logs",
"For example: /path/.logs/error.#YYYY#-#MM#-#DD#-#HH#.log",
"Optional"
],
"packages": [
"</path/to/your/package.json>",
"You can enter paths for multiple package.json files",
"Optional"
],
"disks": [
"/",
"/home/user",
"Optional"
],
"agentidMode": "IP"
}Configure
error_logto view formatted error logs on the Node.js Performance Platform console.Configure
packagesto view project dependencies, their versions, and related security risk alerts.Configure
disksto specify the disks to monitor. This data is available in theSystem Monitoringsection.If you set
agentidModetoIP, a part of the IP address is added to the instance ID. This is useful in scenarios where multiple containers have the samehostname. This configuration is optional.
#YYYY#, #MM#, #DD#, and #HH# are wildcard characters. You can use these wildcards if your error logs are generated based on time.
4. Start the application
Start and monitor your application with the installed Node.js Performance Platform runtime.
Start the application directly
NODE_LOG_DIR=/tmp ENABLE_NODE_LOG=YES node app.jsApplications managed by pm2
NODE_LOG_DIR=/tmp ENABLE_NODE_LOG=YES pm2 start app.jsIf monitoring data does not appear in the console, see the FAQ.