Installing Node.js Agent on Docker


To install APM Insight Node.js agent on Docker container, follow the steps given below:

Note: The below given instructions work only for APM insight Node.js agent versions above 1.7.2. For APM Insight agent versions 1.7.2 and below, refer here.

  1. Download the latest APM Insight Node.js agent (apm_insight_agent_nodejs.zip) file and extract it in the Node.js server.
  2. Open your Node.js application.
  3. Access the node packet manager (NPM).
  4. Use the following command to install an APM Insight Node.js agent from NPM.

    npm install <Node.js-Agent-unzipped-path>/agent_minified

    Example:

    npm install /users/joe/agent_minified

    If you want to deploy APM Insight agent to all the Node.js applications on the computer, use the global option via -g flag.

    npm install -g <Node.js-Agent-unzipped-path>/agent_minified

    Example:

    npm install -g /users/joe/agent_minified

    This will create an APM Insight directory under node_modules.
     
  5. Create a new file named apminsightnode.json in the same directory as your application start file. Add the below code snippet in the file:

    {
      "licenseKey" : "[LICENSE-KEY]",
      "appName" : "[APPLICATION-NAME]",
      "port" : "[APPLICATION-PORT]",
      "apmHost": "[APM-HOST-NAME]",
      "apmPort": "[APM-SSL-PORT]"
    }

    Example:

    {
      "licenseKey" : "APMI_ee420aaaaaaaaaabbbbbbbbbbbbbcccccccccddddddddbe1ea",
      "appName" : "APMInsight_NodeJSapp",
      "port" : "3000",
      "apmHost": "localhost",
      "apmPort": "8443"
    }

  6. If you use proxy connections, enter this code instead:

    {
      "licenseKey" : "[LICENSE-KEY]",
      "appName" : "[APPLICATION-NAME]",
      "port" : "[APPLICATION-PORT]",
      "apmHost": "[APM-HOST-NAME]",
      "apmPort": "[APM-SSL-PORT]"
      "proxyServerHost" : "[PROXY-SERVER]",
      "proxyServerPort" : "[PROXY-PORT]",
      "proxyAuthUser" : "[PROXY-USERNAME]",
      "proxyAuthPassword" : "[PROXY-PASSWORD]"
    }

  7. Include the following code in the first line of your Node.js application start file.

    If using Common JS:
    require('apminsight')()
    If using ES:
    import apminsight from 'apminsight';
    apminsight.config()

  8. Now create/modify the image file named Dockerfile in the directory location of your choice and include the following commands into the image file:

    RUN cd /usr wget https://www.manageengine.com/products/applications_manager/54974026/apm_insight_agent_nodejs.zip
    RUN unzip apm_insight_agent_nodejs.zip
    RUN cd <Node.js-app-path> && npm install /usr/agent_minified

    Example:

    Following is an example of the commands used for configuring the agent into the image file Dockerfile:

    FROM node:16

    WORKDIR /usr/src/app
    COPY . .
    RUN cd /usr wget https://www.manageengine.com/products/applications_manager/54974026/apm_insight_agent_nodejs.zip
    RUN unzip apm_insight_agent_nodejs.zip
    RUN cd /usr/src/app && npm install /usr/agent_minified

    EXPOSE 8080
    CMD [ "node", "server.js" ]

  9. Save the file, rebuild the image and start the container.
Note:
  • The APM Insight Nodejs Agent is incompatible with other profiling tools, such as running the node process with the debugger mode (--inspect switch).
  • If your application uses the cluster module, place the require statement in both the master and worker processes.
  • If you are unable to add application port in apminsightnode.json file, you can add it in your application start file as mentioned below:
    require(‘apminsight’)
    (
    {port:<application port>}
    )

    However other parameters like license key and app name should be added only in apminsightnode.json file.

  • You can also set configuration values like license key, app name, and port as environment variables using the following license keys:
    • License key - APMINSIGHT_LICENSE_KEY
    • App Name - APMINSIGHT_APP_NAME
    • Port - APMINSIGHT_APP_PORT
    • APM Host - APMINSIGHT_APM_HOST
    • APM Port - APMINSIGHT_APM_PORT

For APM Insight agent versions 1.7.2 and below:

We highly recommend you to download the lastest version of APM Insight Node.js agent. But if you are looking to download agent verison 1.7.2 and below for some specific reasons, refer the below given steps:

  1. Download the latest APM Insight Node.js agent (apm_insight_agent_nodejs.zip) file and extract it in the Node.js server.
  2. Open your Node.js application.
  3. Access the node packet manager (NPM).
  4. Use the following command to install an APM Insight Node.js agent from NPM.

    npm install <Node.js-Agent-unzipped-path>/agent_minified

    Example:

    npm install /users/joe/agent_minified

    If you want to deploy APM Insight agent to all the Node.js applications on the computer, use the global option via -g flag.

    npm install -g <Node.js-Agent-unzipped-path>/agent_minified

    Example:

    npm install -g /users/joe/agent_minified

    This will create an APM Insight directory under node_modules.
     
  5. Include the following code in the first line of your Node.js application source code, before any other require statement. Replace the variables with the values for your setup. 

    require('apminsight')({
      licenseKey : '[LICENSE-KEY]',
      appName : '[APPLICATION-NAME]',
      port : [APPLICATION-PORT],
      apmHost: '[APM-HOST-NAME]',
      apmPort: [APM-SSL-PORT]
    })

    Example:

    require('apminsight')({
      licenseKey : 'APMI_ee42094f83dd841d16b9c56796c22b63bef00ac6918f547280947d1f6c2be1ea',
      appName : 'Insight_NodeJS',
      port : 3000,
      apmHost: 'localhost',
      apmPort: 8443 
    })

  6. If you use proxy connections, enter this code instead:

    require('apminsight')({
      licenseKey : '[LICENSE-KEY]',
      appName : '[APPLICATION-NAME]',
      port : [APPLICATION-PORT],
      apmHost: '[APM-HOST-NAME]',
      apmPort: [APM-SSL-PORT]
      proxyServerHost : '[PROXY-SERVER]',
      proxyServerPort : [PROXY-PORT],
      proxyAuthUser : '[PROXY-USERNAME]',
      proxyAuthPassword : '[PROXY-PASSWORD]'
    })

  7. Now create/modify the image file named Dockerfile in the directory location of your choice and include the following commands into the image file:

    RUN cd /usr wget https://www.manageengine.com/products/applications_manager/54974026/apm_insight_agent_nodejs.zip
    RUN unzip apm_insight_agent_nodejs.zip
    RUN cd <Node.js-app-path> && npm install /usr/agent_minified

    Example:

    Following is an example of the commands used for configuring the agent into the image file Dockerfile:

    FROM node:16

    WORKDIR /usr/src/app
    COPY . .
    RUN cd /usr wget https://www.manageengine.com/products/applications_manager/54974026/apm_insight_agent_nodejs.zip
    RUN unzip apm_insight_agent_nodejs.zip
    RUN cd /usr/src/app && npm install /usr/agent_minified

    EXPOSE 8080
    CMD [ "node", "server.js" ]

  8. Save the file, rebuild the image and start the container.