All Products
Search
Document Center

Application Real-Time Monitoring Service:Install the ARMS agent for a Java application deployed in Function Compute

Last Updated:Oct 13, 2023

Application Real-Time Monitoring Service (ARMS) can be connected to the built-in Java 8 runtime of Function Compute. Custom runtimes that use Java 8, Java 11, and Java 17 also support ARMS extension. This topic describes how to connect a custom runtime to ARMS.

Background information

After Function Compute is seamlessly integrated with ARMS, you can use ARMS to monitor and track functions and obtain relevant information, such as instance-level observability, tracing information, Java virtual machine metrics, code-level profiling information, and application security information.

Prerequisite

  • A function in a custom runtime is created and the runtime uses Java 8, Java 11, or Java 17. For more information, see Create a function.

  • The ARMS service is activated. For more information, see Activate ARMS.

Obtain a license key

  1. Log on to the ARMS console. In the left-side navigation pane, choose Application Monitoring > Applications.

  2. On the Applications page, select a region in the top navigation bar and click Add Application.

  3. In the Integration Center panel, click Java. In the STEP2 section, obtain a license key.

    Section LicenseKey

Connect a custom runtime to ARMS

You can integrate ARMS into a custom runtime as an internal extension. The following section describes how to connect a custom runtime to ARMS.

Use a public layer to obtain the ARMS agent

Function Compute uses common layers to provide ARMS agents that support Java 8, Java 11, and Java 17.

Java version

Compatible runtime

Alibaba Cloud Resource Name (ARN) of common layer

Java 11/Java 8

Custom runtime

acs:fc:{region}:official:layers/ArmsAgent273x/versions/2

Java 17

Custom runtime

acs:fc:{region}:official:layers/ArmsAgent273x_JDK17/versions/1

Use a Bootstrap script as startup commands

To use ARMS, you must add three startup parameters. The startup commands are complicated and we recommend that you use a script to perform startup. You can use WebIDE to create the bootstrap file on the function code page and grant executable permissions to the script by running the chmod +x bootstrap command in the terminal. The following sample code provides an example:

#!/bin/bash
set -eo pipefail

#1. Specify a name for the ARMS application.
appName="FC:Custom_Java_Arms_Demo"
if [ -n "${FC_SERVICE_NAME}" ] || [ -n "${FC_FUNCTION_NAME}" ]; then
    appName="FC:${FC_SERVICE_NAME}.${FC_FUNCTION_NAME}"
fi

echo "appName: ${appName}"
params=" "

#2. Add ARMS parameters.
if [[ -n "${FC_EXTENSIONS_ARMS_LICENSE_KEY}" ]]; then
    echo "FC_EXTENSIONS_ARMS_LICENSE_KEY: ${FC_EXTENSIONS_ARMS_LICENSE_KEY}"
    params+="-Dfc.instanceId=$HOSTNAME@`hostname -i` "
    # Use the path of the ARMS program of the common layer.
    params+="-javaagent:/opt/ArmsAgent/arms-bootstrap-1.7.0-SNAPSHOT.jar "
    params+="-Darms.licenseKey=${FC_EXTENSIONS_ARMS_LICENSE_KEY} "
    params+="-Darms.appName=${appName} "
else
    echo "The environment FC_EXTENSIONS_ARMS_LICENSE_KEY does not exist, please set the FC_EXTENSIONS_ARMS_LICENSE_KEY environment!"
    exit 1
fi

#3. Launch the application.
echo "params: ${params}"
exec java $params \
    -Dserver.port=9000 \
    -jar /code/target/demo-0.0.1-SNAPSHOT.jar

In the preceding code:

  1. Specify a name for the ARMS application. The default value is FC:{ServiceName}.{FunctionName}.

  2. Add ARMS parameters.

    • javaagent: the path of the ARMS program. If the common layer of the ARMS agent is used, the path is /opt/ArmsAgent/arms-bootstrap-1.7.0-SNAPSHOT.jar.

    • Darms.licenseKey: the information about the license key. In this example, the license key is obtained from environment variables. For information about how to obtain a license key, see the "Obtain a license key" step in Install the ARMS agent for a Java application in Function Compute.

    • Darms.appName: the name of the ARMS application. Use your actual ARMS application name.

Configure environment variables

  • Set the FC_EXTENSIONS_ARMS_LICENSE_KEY=xxxx environment variable to the value of the license key. For information about how to obtain a license key, see the "Obtain a license key" step in Install the ARMS agent for a Java application in Function Compute.

  • Configure the FC_EXTENSION_ARMS=true environment variable.

    After the environment variable is added, the function instance is frozen 10 seconds after a function invocation is completed. This ensures that the ARMS agent can report logs as expected.

    Important

    If you use this method, you are charged for the fees generated. The billing method is the same as the billing method of the Prefreeze hook of the instance. For more information, see Billing rules.

Procedure

  1. Log on to the Function Compute console. In the left-side navigation pane, click Services & Functions.
  2. In the top navigation bar, select a region. On the Services page, click the desired service.
  3. On the Functions page, find the desired function and click Configure in the Actions column.
  4. In the Layers section of the function configurations page, click Add Official Common Layer to add an ArmsAgent layer that is compatible with the Java version.

  5. In the Environment Variables section of the function configurations page, add the FC_EXTENSION_ARMS=true and FC_EXTENSIONS_ARMS_LICENSE_KEY=xxxx environment variables.

    For more information, see Configure environment variables.

  6. In WebIDE of the function code page, create a bootstrap file and click Deploy.

    For more information, see Use a Bootstrap script as startup commands.

    After you update the configurations and deploy the code, the function is added to ARMS for high-performance management. You are charged for using ARMS. For more information, see Billing overview.

Important
  • If you want to view monitoring information after your function is connected to ARMS, make sure that ARMS resides in the same region as your function.

  • Make sure that the memory size of your function is greater than 512 MB because ARMS consumes approximately 300 MB of memory.

Verify the result

After you connect a function to ARMS, you can view the function in the ARMS console.

You can also log on to the ARMS console. In the left-side navigation pane, choose Application Monitoring > Applications. Click the name of the desired application to view the monitoring information. For more information, see Application overview.

Note

The name of the target application is the value of appName in the Bootstrap script. The default value is FC:{ServiceName}.{FunctionName}.