The Agent Download Wizard in the Controller provides the easiest way to get started quickly with the AppDynamics Node.js Agent. The wizard constructs a pre-configured require statement for the agent based on your input.
This page provides additional information and options for installing the Node.js Agent.
Prepare to Install the Node.js Agent
You must add a require statement to the source code of your Node.js application to install the Node.js agent. Therefore, in addition to a running AppDynamics Controller, you need to have write access to the application source code and the ability to restart the Node.js application to install the agent.
The Getting Started wizard in the AppDynamics controller can generate the require statement for you. It populates the statement with the connection settings for the controller and the values you provide to the wizard for modeling the Node.js application in AppDynamics.
For Installations on Windows:
- Verify support for your version of Windows.
- Install the Visual C++ Redistributable for Visual Studio 2015.
About Node.js Agent Node Identity
You configure the identify of a node.js application instance using the node name setting. By default, the agent uses the value configured for
nodeName as a prefix and adds a dash and number as a suffix. For example, given the following setting:
The first node to start with this configuration would be named
MyNode-0. Auto-numbered suffixes on node names are most useful for machines with more than one worker process.
If you are not running multiple worker processes, you can prevent auto-numbering in node names by setting
true. In the following example, the node would be named MyNode.
Running the Machine Agent on a Node.js Node
If you install the Standalone Machine Agent on the machine hosting the instrumented Node.js node and you specify the tier and node name in the
controller-info.xml file of the machine agent, the Node.js Agent will fail to register.
To avoid this problem:
- Install the Node.js Agent before you install the Standalone Machine Agent.
- If you install the machine agent on the machine hosting the instrumented Node.js node, do not specify the application, tier or node name in the machine agent's
controller-info.xmlfile. If you do, the Node.js Agent may fail to register.
Installing the Node.js Agent
To install the agent, run the npm installation command in each directory you want to monitor and then add a require command to add the agent module to your application.
If you are using Node.js 0.8.1 through 0.8.18, see Set User Agent for Node.js 0.8.1 through 0.8.18.
Installing via npm
Refer to Agent and Controller Compatibility to determine which versions of the AppDynamics Node.js agent are compatible with your controller.
To install the latest 4.5 agent, run the following command:
If you know which specific version of the Node.js agent you want to install, you can specify it:
If you are using npm 5, you must disable the lock file by setting
package-lock=false in the npm configuration settings.
Installing Node.js with Java proxy
To install Node.js with Java proxy run the following command at the time of agent install:
--appd_include_java_proxy npm configuration option is not provided, the npm install command installs only the libagent dependencies.
Add the Require Statement
Paste the following require statement as the very first line of your application source code, before any other require statement. Replace the variables with the values for your setup. To find your account name and access key, click the settings () icon in the upper right corner of the AppDynamics UI, and then click License.
For reference information on the settings, along with other settings you can use, see Node.js Settings Reference.
You can place the
require statement as the first line in the require statement of another module that appears as the first line of code.
In this case, you would need to modify your point-of-entry source file; this it can be just a single line to the require() the file that you place the call to the agent into; for example,
require(“<script-that-initializes-the-agent>”. You could also parameterize the profile() call to name different instances without having to have multiple versions of the agent initialization script.
If it is not possible to place the require statement as the first line of code, you can insert the statement elsewhere, but it must occur before the require() of any core or third party module that needs to be instrumented. In general, the
require(“appdynamics”) statement should occur as early as possible in the code.
Test the Configuration
To verify the installation, restart the application and put load on it. The new node should appear in the flow map for the business application you specified in the configuration.
Stopping the Node.js Application
The script or other mechanism used to stop an instrumented Node.js instance should use the SIGTERM signal if possible.
Using SIGKILL (kill -9) will prevent resources for the agent's Java proxy to be properly released.
Running with other profiling tools
The agent is incompatible with other profiling tools, such as running the node process with the
Instrumenting a Node.js Cluster
If your application uses the cluster module, place the
appdynamics.profile require statement in both the master and worker processes. This scenario does not require a manual launch of the proxy.
If your application uses an external process manager, such as PM2, you need to launch the proxy component manually. See Sharing a Proxy Among Node.js Agents
Set User Agent for Node.js 0.8.1 through 0.8.18
If running a Node.js version between 0.8.1 and 0.8.18, inclusive, you need to set the
user-agent npm property before you run the
npm install command.
The syntax is:
Resolving Installation Issues for Node.js
If you are trying to install the Node.js Agent on a version of Node.js that the agent does not support, the installation will fail and you will see a message similar to the following:
See Node.js Versions in Node.js Supported Environments