cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Monitoring Nodejs with pm2

jose.antonio.ruiz
New Member

Hi, good morning.

I'm testing Appdinamyc nodejs monitor.
I have verified that it works perfectly.
But I have problems when I use the application manager nodejs "pm2" to start them with "n instances".
How can I configure Appdynamics with pm2 nodejs?

 

6 REPLIES 6

Ayush.Ghosh
AppDynamics Team

Hi,

 

If you want to use a process manager like PM2, you need to start the proxy manually. 

 

AppDynamics NodeJs agent talk to the controller via a proxy, there should be only one instance of proxy running. When you use a process manager like PM2. It may start multiple proxy which creates issue.

 

Here is the documentation to start the proxy manually. 

 

https://docs.appdynamics.com/display/PRO42/Run+the+Proxy+Daemon+Manually+for+Node.js+Agents

 

 

 

Hi, thaks.

I followed your instructions but I always fail because I can not find the directory.
I have tried to create the directories tmp / appd / tmp / appd / logs and / tmp / appd / proxy_ctrl_dir

 

I have execute:

 

[nodejs@svtarqfrt1re proxy]$ ./runProxy -j /appsrv/LIBERBANK.PROYECTO/LBK_ARQ_SPA_SERVER/node_modules/appdynamics/node_modules/appdynamics-jre/jre - /tmp/appd/proxy_ctrl_dir /tmp/appd/logs/
Proxy communication directory, "-", does not exist or is not a directory.
Usage: runProxy options -- proxyCommunicationDir logDirectory [jvmOption [ jvmOption [...] ]
Options:
  -r <dir>, --proxy-runtime-dir=<dir>   Specifies proxy runtime directory
  -d <dir>, --proxy-dir=<dir>           Specifies root proxy directory
  -j <dir>, --jre-dir=<dir>             Specifies root JRE directory
  -v, --verbose                         Enable verbose output
  -h,--help                   Show this message

Example: ./runProxy -d ./proxy -r /tmp/appd/app1/tier1/node1 /tmp/proxy.communication /tmp/agentLogs
Note: Please use quotes for the entries wherever applicable.


But always getting the following error


"Proxy communication directory," - ", does not exist or is not a directory."
Would be kind enough to show me some example.
Many thank

 

Ayush.Ghosh
AppDynamics Team

Explaining a bit further.

 

If the process manager spins up only 1 instance, it will work perfectly. As its same as just running application with node app.js.

 

But if you use of PM2 is to run multiple processes/instances, in which case there may be an issue. As with each instance a new proxy could be spinned.

 

Thus we suggest starting the proxy manually, and the steps are as follows

 

Create two directories /tmp/appd/proxy_ctrl_dir/tmp/appd/logs

 

In Appdynamics config for NodeJS

 

Set proxyCtrlDir as /tmp/appd/proxy_ctrl_dir

Set proxyAutolaunchDisabled as true

 

Then start the proxy manually as described in the documentation 

nohup /<application_root_dir>/node_modules/appdynamics-proxy/proxy/runProxy -j /<application_root_dir>/node_modules/appdynamics-jre/jre – /tmp/appd/proxy_ctrl_dir /tmp/appd/logs & 

 

https://docs.appdynamics.com/display/PRO42/Run+the+Proxy+Daemon+Manually+for+Node.js+Agents

 

Then start the NodeJs application so that with any number of instance, there is only one proxy.

 

 

 

 

 

 

 

 

sorry for delay. .

I`ll summarize the actions

I first  started correctly started manualy proxy

second started pm2 -i 2 start server.js

but no monitoring .

Also be where to put  these options

  • Configure each agent for manual launch of the proxy. In the AppDynamics require.profile() block of each Node.js process, set proxyAutolaunchDisabled to true and set the proxyCtrlDir to the directory that you created. For example:

    ...
    proxyAutolaunchDisabled: true,
    proxyCtrlDir: '/tmp/appd/proxy_ctrl_dir',
    ...

 

very best regards

Hi,

 

In your node application you initiate the appdynamics profiler like

 

require("appdynamics").profile({
  controllerHostName: '<controller host name>',
  controllerPort: <controller port number>, 
  controllerSslEnabled: false,  // Set to true if controllerPort is SSL
  accountName: '<AppDynamics_account_name>',
  accountAccessKey: '<AppDynamics_account_key>', //required
  applicationName: 'your_app_name',
  tierName: 'choose_a_tier_name', 
  nodeName: 'choose_a_node_name', 
 });

 

You need to add the 

proxyAutolaunchDisabled: true,
proxyCtrlDir: '/tmp/appd/proxy_ctrl_dir',

 

to the same block.

 

Please remember to start proxy first, and use the same file location for control and logs directory.

 

 

Thanks

Ayush

 

 

 

 

 

PM2 gained the most popularity and is now considered an enterprise standard. One of the most important thing is that It’s in active development, has a stable API and is constantly assailed by more than 1000 tests. If you are interested in monitoring & scaling Node.js apps you should read this article https://www.netguru.co/codestories/monitoring-vertically-scaling-nodejs-applications. It's definitely worth it. :)