Updated on 2025-04-27 GMT+08:00

Installing Agents on Docker Applications

Prerequisite

  • The network between your host and APM is normal. You can run the curl -kv command to check the network. For example, if you select region CN-Hong Kong and set Access Mode to Enhanced Agent, log in to the host where the application is deployed and run the curl -kv 100.125.6.106:41333 command to check the network connectivity. For details about access addresses in other regions, see Agent Access Addresses.
  • Java supports enhanced Agents.

Procedure

  1. Log in to the management console.
  2. Click on the left and choose Application > Application Performance Management.
  3. In the navigation pane, choose Application Monitoring > Applications.
  4. On the displayed page, click Connect Application.

    Figure 1 Connecting an application

  5. Select a region and an application.Click Create Application. On the displayed page, create an application by referring to Creating an Application.

    Figure 2 Basic information

  6. Select Enhanced Agent for Access Mode.
  7. Select Java for Backend Language.

    Figure 3 Access mode

  8. Use a remote login tool, such as PuTTY, to log in to the Linux host where the Agent is to be installed and run related commands as the root user.
  9. Select an access mode based on the application type and access data by following the instructions.

    Figure 4 Data access
    Table 1 Parameter description

    Parameter

    Description

    Mandatory

    APM_AK

    APM_SK

    AK and SK for installing JavaAgent. To obtain APM_AK and APM_SK, see Access Keys.

    When you copy the command to install JavaAgent, delete {} when setting APM_AK and APM_SK.

    Example:

    curl -k https://javaagent.***/apm_agent_install2.sh -o apm_agent_install.sh && bash apm_agent_install.sh -ak * -sk * -masteraddress https://**** -obsaddress https://javaagent.***.com -version latest; history -cw; history -r 

    Yes

    masteraddress

    Access address. For details, see Agent Access Addresses.

    Yes

    version

    Agent version. The latest Agent provided by APM supports multiple JDK environments.

    Yes

    Probe Installation Path

    Path for installing the Agent.

    Yes

    appName

    Component name, which must start with a letter. A component can contain multiple environments. The names of components under an application must be unique. If there are duplicate names, use instanceName to distinguish them.

    Yes

    env

    Name of an environment where an application is deployed. A program can be deployed in different environments (such as the test or live network environment). Each environment is deployed in one region and has a unique region attribute. If this parameter is blank, the default environment will be used.

    No

    envTag

    Environment tag for filtering environments. Different environments may have the same tag. This parameter can be left blank.

    No

    business

    Name of an application that already exists (a global concept). If this parameter is left blank, the automatically created application will be used.

    No

    subBusiness

    Name of a sub-application (a global concept), which is similar to a folder. If it is left blank, resources will be mounted to the root application. There can be up to three layers of sub-applications. For example, for a/b/c, a, b, and c respectively represents a layer.

    No

    User Application

    Name of a user application.

    Yes

  10. Add the copied command to the Dockerfile file and add the JAVA_TOOL_OPTIONS environment variable.

    RUN curl -k https://javaagent.obs.xx-xxx-x.xxxx.huawei.com/apm_agent_install2.sh -o apm_agent_install.sh && bash apm_agent_install.sh -ak {AK}-sk {SK} -masteraddress https://xxx.xx.xx.xx:xxx -obsaddress https://javaagent.obs.xx-xxx-x.xxxx.huawei.com -version latest
    
    ENV JAVA_TOOL_OPTIONS=-javaagent:${PROJECT_DIR}/apm-javaagent/apm-javaagent.jar=appName=${APP_NAME}

  11. Rebuild an image. The following is an example of the Dockerfile file.

    FROM openjdk
    RUN mkdir /opt/cloud 
    ENV PROJECT_DIR=/opt/cloud
    ENV APP_NAME=hello
    WORKDIR $PROJECT_DIR
    ADD ${APP_NAME}.jar ${APP_NAME}.jar
    RUN curl -k https://javaagent.obs.xx-xxx-x.xxxx.huawei.com/apm_agent_install2.sh -o apm_agent_install.sh && bash apm_agent_install.sh -ak {AK}-sk {SK} -masteraddress https://xxx.xx.xx.xx:xxx -obsaddress https://javaagent.obs.xx-xxx-x.xxxx.huawei.com -version latest
    ENV JAVA_TOOL_OPTIONS=-javaagent:${PROJECT_DIR}/apm-javaagent/apm-javaagent.jar=appName=${APP_NAME}
    CMD ["bash","-c","java -jar ${APP_NAME}.jar" ]

  12. Redeploy the application.