Updated on 2023-07-20 GMT+08:00

Connecting an ECS Application to APM

If your application is deployed on an Elastic Cloud Server (ECS), learn APM based on the following procedure. This section describes how to connect a Java application on an ECS server to APM for monitoring.

Prerequisites

Procedure

Step 1: Subscribe to APM

See Subscribing to APM and Buying a Package.

Step 2: Install the ICAgent

  1. Obtain an Access Key ID/Secret Access Key (AK/SK).
  2. Log in to the APM console.
  3. In the navigation pane, choose Agent > Management.
  4. Click Install ICAgent. On the page that is displayed, set Host to HUAWEI CLOUD host and OS to Linux.
  5. Select the Obtain AK/SK installation mode, enter the obtained AK/SK in the text box to generate the ICAgent installation command, and click Copy Command.

    Ensure that the AK/SK are correct. Otherwise, the ICAgent cannot be installed.

  6. Remotely log in to the ECS server as the root user and run the preceding command to install the ICAgent.

    When the message "ICAgent install success" is displayed, the ICAgent is successfully installed in the /opt/oss/servicemgr/ directory.

(Optional) Step 3: Modify Permissions

If you start the program as a non-root user, run the following commands to modify the permissions on the probe file and output directory before enabling application monitoring:

chmod -R 777 /opt/oss/servicemgr/ICAgent/pinpoint/
mkdir -p /paas-apm/collectors/pinpoint
chmod -R 777 /paas-apm

Step 4: Configure the Application Startup Script and Restart the Application

  1. On the ECS server, if you do not use Tomcat to start the service, perform the following operations:
    1. Add the configuration items in the following table to the place below the java keyword in the Java application startup script to ensure that the Java application can be monitored by APM.
      Table 1 Configuration items to be added

      Parameter

      Description

      -javaagent

      JAR package that collection probes depend on

      The fixed value is /opt/oss/servicemgr/ICAgent/pinpoint/pinpoint-bootstrap.jar.

      -Dapm_application

      Application name.

      The value must be 1 to 64 characters starting with a letter or an underscore (_). Only lowercase letters, digits, hyphens (-), and underscores are allowed.

      -Dapm_tier

      Application microservice name.

      The value must be 1 to 64 characters starting with a letter or an underscore (_). Only lowercase letters, digits, hyphens (-), and underscores are allowed.

      Example of the modified startup script

      The following shows an example startup script of the Vmall application with the vmall-dao-service and vmall-user-service services. You need to configure your script as required.
      • Original startup script:
        java -Xmx512m -jar /root/testdemo/ecommerce-persistence-service-0.0.1-SNAPSHOT.jar --spring.config.location=file:/root/testdemo/application_dao.yml > dao.log 2>&1 &
        java -Xmx512m -jar /root/testdemo/ecommerce-user-service-0.0.1-SNAPSHOT.jar --spring.config.location=file:/root/testdemo/application_userservice.yml > user.log 2>&1 &
      • Modified startup script (differences are in bold):
        java -javaagent:/opt/oss/servicemgr/ICAgent/pinpoint/pinpoint-bootstrap.jar -Dapm_application=vmall -Dapm_tier=vmall-dao-service -Xmx512m -jar /root/testdemo/ecommerce-persistence-service-0.0.1-SNAPSHOT.jar --spring.config.location=file:/root/testdemo/application_dao.yml > dao.log 2>&1 &
        java -javaagent:/opt/oss/servicemgr/ICAgent/pinpoint/pinpoint-bootstrap.jar -Dapm_application=vmall -Dapm_tier=vmall-user-service -Xmx512m -jar /root/testdemo/ecommerce-user-service-0.0.1-SNAPSHOT.jar --spring.config.location=file:/root/testdemo/application_userservice.yml > user.log 2>&1 &
    2. Execute the modified application startup script to enable application monitoring.
  1. On the ECS server, if you use Tomcat to start the service, perform the following operations:
    1. Go to the bin directory of Tomcat.
    2. Copy the following content to the catalina.sh file.
      JAVA_OPTS="$JAVA_OPTS -javaagent:/opt/oss/servicemgr/ICAgent/pinpoint/pinpoint-bootstrap.jar -Dapm_application=xxx -Dapm_tier=xxx"

      -Dapm_application -Dapm_tier needs to be configured based on Table 1.

    1. Execute the modified application startup script to enable application monitoring.

Step 5: Manage the Application on APM

Three minutes after the application is started, its data will be displayed on the APM console. You can log in to the APM console and optimize application performance through topology and tracing. For details, see APM User Guide.