Installing Node.js Agent on Docker


Installation steps for Node.js agent versions 4.0.0 & above

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 4.0. For APM Insight agent versions below 4.0 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. 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"
    }

  4. 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]"
    }

  5. Include the following code point(5) in the first line of your Node.js application start file.
  6. If using Common JS:
    require('apminsight');
    If using ECMAScript:
    import apminsight from 'apminsight';
    If using TypeScript
    import AgentAPI from apminsight';
    AgentAPI.config();

  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.
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.
  • 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
    • proxyServerHost - APMINSIGHT_PROXYSERVER_HOST
    • proxyServerPort - APMINSIGHT_PROXYSERVER_PORT
    • proxyAuthUser - APMINSIGHT_PROXYAUTH_USER
    • proxyAuthPassword - APMINSIGHT_PROXYAUTH_PASSWORD
 

Installation steps for Node.js agent above 1.7.2 and below 4.0.0

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

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 required 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. 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"
    }

  4. 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]"
    }

  5. 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()

  6. 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" ]

  7. 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
 

Installation steps for Node.js agent versions 1.7.2 and below

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

  1. Download the required 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. 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 
    })

  4. 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]'
    })

  5. 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" ]

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