You must add an agent data collector to your Node.js application and restart it before
the agent can start monitoring your application.
Before you begin
Before you reconfigure the agent settings within the same version, use the
following steps to clean the data collector files that were created by the previous configuration:
- Go to the install_dir/lx8266/nj/bin directory.
- Run the
./uninstall.sh
command to remove existing data collector files.
About this task
The Node.js agent is a single instance agent. It registers subnodes for each monitored Node.js
application. The subnode is in the following structure:
NJ:hostname_port:NJATip: If one Node.js application
listens on multiple port numbers, then the lowest port number is used.
You must add an agent data collector to your Node.js application, and restart your
application before the agent can begin monitoring your application. The agent data collectors
collect data that is forwarded to the Node.js agent. Currently, the following agent data collectors
are provided:
- The resource data collector collects resource monitoring data from your Node.js
applications.
- The diagnostics data collector collects diagnostic data and resource monitoring data from your
Node.js applications.
- The method trace data collector collects method traces, diagnostics data, and
resource monitoring data from your Node.js applications.
Procedure
-
Make sure that the user ID that is used to run the application server has full permission to
the install_dir directory of the agent.
-
Go to the directory install_dir/bin and run the following command:
-
Follow the prompts to specify values for the following configuration options:
- KNJ_NODEJS_RUNTIME_BIN_LOCATION
- The directory to the bin folder of your Node.js runtime. The default
directory is /usr/local/bin.
- KNJ_NPM_RUNTIME_BIN_LOCATION
- The directory to the bin folder of you npm command. The
default directory is /usr/local/bin.
- KNJ_NPM_LIB_LOCATION
- The directory to the lib folder of your npm package global installation
directory. The default directory is /usr/local/lib. For example, if you install
npm package by running
npm install -g
command, the package is installed to
/nodejs_home/lib/node_modules and the
KNJ_NPM_LIB_LOCATION is
/nodejs_home/lib.
- CP_PORT
- The port that the agent listens on for data from socket clients. A value of
0
indicates that an ephemeral port will be used. The default value is 63336
.
Note: Don't use the port number that is already used in your system. To check whether the port is
already in use, run the netstat -apn | grep port_number
command.
-
Start the agent by running the following command:
-
Verify that the Node.js agent is started successfully. The KNJ_NPM_LIB_LOCATION/node_modules/ibmapm folder is generated if the
agent starts successfully.
-
Based on the offering that you have and your requirements, insert one of the following entries
to the .js file of your Node.js application to configure the agent data
collectors:
Note: Only one entry can be added to your Node.js application to enable agent data collector
capabilities. Also, if you enable capabilities that are not included in the offering, unnecessary
overhead can happen, which decreases application execution efficiency.
- If you have only resource monitoring capabilities, you can add the resource data collector.
To add it, insert the following line in the beginning of the Node.js application file:
require('KNJ_NPM_LIB_LOCATION/node_modules/ibmapm');
If the
value of KNJ_NPM_LIB_LOCATION on your environment is
/usr/local/lib, the line is
require('/usr/local/lib/node_modules/ibmapm');
- If you have diagnostics in addition to resource-level monitoring capabilities, you can
choose to add one of the following agent data collectors:
- To add the method trace data collector, insert the following line in the beginning of the
Node.js application
file:
require('KNJ_NPM_LIB_LOCATION/node_modules/ibmapm/methodtrace.js');
- To add the diagnostics data collector, insert the following line in the beginning of the Node.js
application
file:
require('KNJ_NPM_LIB_LOCATION/node_modules/ibmapm/deepdive.js');
- To add the resource monitoring data collector, insert the following line in the beginning of the
Node.js application
file:
require('KNJ_NPM_LIB_LOCATION/node_modules/ibmapm');
To guarantee best performance, add the method trace data collector only for debugging
purposes.
Note: The code of the plug-ins changes from Cloud APM,
Private
V8.1.4. If you upgrade your agent from
earlier versions, you must update the code of the existing data collectors in your applications for
the monitoring ability to work properly.
-
Restart your Node.js application to enable the agent data collector.
Results
You have successfully configured the Node.js agent.