All Products
Search
Document Center

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

Last Updated:Oct 12, 2024

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.

Prerequisites

  • 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 version of the JDK is supported by Application Monitoring. For more information, see Java components and frameworks supported by ARMS.

  • The maximum heap memory of the process is greater than 256 MB.

Obtain a license key

Obtain a license key in OpenAPI Explorer. For more information, see DescribeTraceLicenseKey.

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 ARMS agents

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

Java version

Compatible runtime

Common layer ARN

Java 11/Java 8

Custom runtimes

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

Java 17

Custom runtimes

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

Use a bootstrap script to start an application

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 a bootstrap file on the function code page and configure executable permissions for the file by running the chmod +x bootstrap in the terminal. The following 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_FUNCTION_NAME}" ]; then
    appName="FC:${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

The following items describe the details of the sample code:

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

  2. Add ARMS parameters.

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

    • Darms.licenseKey: the license key information. In this example, the license key is obtained from environment variables. For more information about how to obtain a license key, see Obtain a license key.

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

Configure environment variables

  • Configure the environment variable FC_EXTENSIONS_ARMS_LICENSE_KEY=xxxx. Set the value to the license key. For more information about how to obtain the license key, see Obtain a license key.

  • Set the environment variable FC_EXTENSION_ARMS=true.

    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

    You are charged for using the FC_EXTENSION_SLS_LOGGIE=true environment variable. The billing rules of the environment variable are the same as the billing rules of PreFreeze hooks. For more information, see Billing overview.

Procedure

  1. Log on to the Function Compute console. In the left-side navigation pane, click Function.

  2. In the top navigation bar, select a region. On the Function page, click the name of the function that you want to manage.

  3. On the page that appears, click the Configuration tab.

  4. In the left-side navigation pane, click Layers. On the page that appears, click Modify. In the Layers panel, choose + Add Layer > Add Official Common Layer to add an ARMS agent layer that is compatible with your Java runtime.

  5. In the left-side navigation pane, click Environment Variables. On the page that appears, click Modify to add the FC_EXTENSION_ARMS=true and FC_EXTENSIONS_ARMS_LICENSE_KEY=xxxx environment variables.

    For more information, see Configure environment variables.

  6. In the 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.

Check the execution result of an HTTP job

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

Note

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