All Products
Search
Document Center

Function Compute:ARMS extensions for custom runtimes

Last Updated:Jul 11, 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

Function Compute seamlessly integrates with ARMS. You can use ARMS to monitor and trace functions to obtain relevant information, such as metrics of instances, tracing data, Java Virtual Machine (JVM) metrics, code-level profiling and application security information. For more information, see What is ARMS?.

Information

Description

Metrics of instances

You can view various host metrics for instances, such as metrics that are related to the CPU, the memory, and requests.

Tracing data

The ARMS agent automatically obtains the topological relationships between a function and its upstream and downstream components and related metrics. You can view the information about the components such as databases and message queues in the ARMS console.

JVM metrics

The ARMS agent automatically obtains JVM applications. You can view the monitoring information of the JVM applications in the ARMS console, such as the number of garbage collections (GCs), heap information, and thread stack information.

Code-level profiling information

You can view code-level profiling information of function execution, such as the amount of time consumed by each method and errors.

Application Security

Application Security is developed based on the Runtime Application Self-Protection (RASP) technology. Application Security can provide runtime self-protection for applications and protect your applications against the attacks that attackers exploit most unknown vulnerabilities to launch.

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.

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.

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