Agent Installation for node.JS
About Cavisson NetJSAgent Agent
Cavisson NetJSAgent is a JavaScript based agent for instrumenting Node.js application. It is similar to Cavisson NetDiagnostics BCI agent which is used to instrument Java based enterprise application. Cavisson agent is already published on Node.js Node Package Manager (NPM) repository as well as on GitHub and is available for download.
Node Package Manager (NPM): NPM is a program for managing packages and dependencies.
GitHub: GitHub is a web-based Git repository hosting service. It offers all of the distributed version control and source code management (SCM) functionality of Git as well as adding its own features.
Terminologies Used
Term | Description |
Netjsagent | Node.js agent |
ndcHost | NetDiagnostics Collector IP or hostname |
ndcPort | NetDiagnostics Collector listening port |
Pre-Installation Requirements
This section describes all the prerequisites of the server where NetDiagnostics Agent will be installed.
Detailed requirements include:
- Platform requirements
- Storage requirements
Platform/OS
Following platforms are supported for both 32 and 64-bit architype.
- Linux
- Solaris
- Windows
Storage requirements
Minimum disk space of 256 Megabytes (4 Mb installation files plus logs)
Steps to Install NetJSAgent
The installation procedure contains installation of Node.js (if not already installed) and adding the required javaagent argument to the command line startup parameters of the Node.js.
Please note that Node.js should be installed on your system. If not installed, refer the following steps for the installation.
Installing Node.js
Node.js is an open-source, cross-platform runtime environment for developing server-side Web applications.
- Download Node.js from https://nodejs.org.
- Install Node.js using the following commands.
$ cd ~/Downloads $ mkdir -p ~/local/node $ tar xzf node-v0.10.7-linux-x64.tar.gz -C ~/local/node --strip-components=1 $ echo '# Node Environment Setup' >> ~/.bashrc $ echo 'export PATH=$HOME/local/node/bin:$PATH' >> ~/.bashrc $ echo 'export NODE_PATH=$HOME/local/node/lib/node_modules' >> ~/.bashrc $ . ~/.bashrc
- To check Node.js is installed or not, use the following commands.
node -v npm -v
If it is installed, you will get the output similar to the following:
netstorm@netstorm-HP-650-Notebook-PC:~/Desktop$ node -v v0.12.6 netstorm@netstorm-HP-650-Notebook-PC:~/Desktop$ npm -v 2.11.2
Installing the agent and adding command line arguments
Steps required to install NetJSAgent to client application:
- Open the Node js application directory.
- Add dependency of NetJSAgent library in json file of client application.
- Open package.json configuration file of client application and add the following line under dependencies section in package.json:
"netjsagent" : "<version #>" For e.g.: “netjsagent” : “0.2.40
(For latest version of agent, check it on https://www.npmjs.com/ and search netjsagent)
- Open the main file of application from where your application is starting, it could be Index.js, App.js or anything. In case you don’t know the main file, you can find it from package.json, entry of main file is provided in it.
For example,
"scripts": { "start": "node ./bin/www" <-- This is main file of application }
Open this file and insert following line in the beginning of file in order to bootstrap Node_agent in client application:
try{require('netjsagent').instrument ({logLevel:'debug',BCILoggingMode : 'FILE'});}catch(err) {console.log(err)}
- Create a file called ndSettings.conf in the main directory of your project. This file contains the address of the NS machine with whom you have to make connection.
tier=TierName ndcHost=NDCHost ndcPort=NDCPort
For Example:
For profiling single application on a VM, details in config file should be as below:
Sample content:
tier=NodeJS ndcHost=10.206.249.62 ndcPort=7892
- Create another file for Business transactions called txt in the main directory of your project. This file is optional. If you create this file, then BT_Trend will come according to this file, else BT_Trend will come according to URLs. In this file, provide all the entries of all URLs with some BT_Name.
For example,
#Recod_No|BT_Name|Index|BTMatch_Mode|BT_Include_Mode|URL_Pattern 7|Others|0|0|1|/ 7|Index|1|0|1|/nsecomm 7|ManyTier|2|0|1|/nsecomm/manyTier
Note: This is a reference for local environment only.
- To download this module (netjsagent), run command npm install in the main directory of application. (For npm lib installation)
- To enable all these changes, restart the client application.
Parameter | Description |
ndSettings.conf | This file contains the address of the NS machine for connection. |
ndBtRuleFile.txt | File for business transactions. |
*tier | The logical tier. |
*server | The display or actual name of the server where the agent is running. This can take both hostname and IP |
Instance | The name of the standalone application instance or managed instances |
*ndcHost | The legitimate ndcHost. |
*ndcPost | The legitimate ndcPort for the agent to connect back |
Note:
- Fields marked with asterisks (*) has to be provided by monitoring team or the overseas team which would be responsible for monitoring the application instance.
- It is mandatory to restart the servers to mark the installation as complete.
Steps to Uninstall NetJSAgent
Follow the below mentioned steps for uninstalling NetJSAgent.
- Remove the entry of netjsagent from package.json.
- Remove the following line from Index.js file of client application:
var netjsagent = require('netjsagent').instrument();
- To enable all these changes, restart the client application.