All Products
Search
Document Center

Application Real-Time Monitoring Service:Use an ARMS agent for Go in Function Compute

Last Updated:Nov 20, 2024

This topic describes how to connect the Go runtime in Function Compute to Application Monitoring of the Application Real-Time Monitoring Service (ARMS).

Background information

If Function Compute connects to Application Monitoring of ARMS, you can monitor and trace functions, gaining insights into instance-level observability, trace data, Go runtime metrics, and CPU profiling.

Prerequisites

  • The application uses Go V1.18 or later.

  • A license key is available. For more information, see DescribeTraceLicenseKey.

Method 1: Create a function using the compiled Go binary file in Function Compute

  1. Use the ARMS agent for Go to compile the Go application. For more information, see Step 1: Compile the Go binary file.

  2. Upload the compiled Go binary file to Function Compute. For more information, see Create an event function.

    image

  3. Set environment variables.

    TYPE_IS_ARMS=true
    ARMS_APP_NAME=xxx   # The application name.
    ARMS_REGION_ID=xxx   # The Region ID of the Alibaba Cloud account.
    ARMS_LICENSE_KEY=xxx   # The license key.

    image

  4. Run the function. Then, you can choose Application Monitoring > Application List and view the configured application in the ARMS console.

    Click the application name. On the Overview page, you can monitor the number of requests, number of errors, average processing time, and other call metrics of the application.

    image

Method 2: Build a Go application in Function Compute

  1. Modify actions in the s.yaml file. For more information, see What is Serverless Devs?

    • The following code is an example for the China (Hangzhou) region. Change the address to the one for downloading the compilation tool based on your operating system and region. For more information, see Get a download address.

    • Change the license key in the code to the one you have obtained.

    edition: 3.0.0
    name: hello-world-app
    access: "{{ access }}"
    
    vars: # The global variable.
      region: "{{ region }}"
    
    resources:
      hello_world:
        component: fc3 
        actions:       
          pre-${regex('deploy|local')}: 
            - run: GO111MODULE=on go mod tidy
              path: ./code
            - run: wget "http://arms-apm-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/instgo/instgo-linux-amd64" -O instgo
              path: ./code
            - run: chmod +x instgo
              path: ./code
            - run: GOOS=linux GOARCH=amd64 CGO_ENABLED=0 ./instgo build --licenseKey="{licenseKey}" --cacheDir=./ -- -o target/main main.go
              path: ./code
        props:
          region: ${vars.region}              
          functionName: "{{ functionName }}"
          description: 'A simple hello world application by serverless devs'
          runtime: "{{ runtime }}"
          code: ./code/target
          handler: main
          memorySize: 128
          timeout: 10
          # Triggers:
          #   - triggerName: httpTrigger # The trigger name.
          #     triggerType: http # The trigger type.
          #     description: 'xxxx'
          #     qualifier: LATEST # The version of the triggered service.
          #     triggerConfig:
          #       authType: anonymous # The authentication type. Valid values: anonymous and function.
          #       disableURLInternet: false # Specifies whether to disable the URL for accessing the public network.
          #       methods: # The access method supported by the HTTP trigger. Valid values: GET, POST, PUT, DELETE, and HEAD.
          #         - GET
          #         - POST
  2. In the Function Compute console, choose Applications and click Import an Application from a Repository to import an application. For more information, see Manage applications.

    image

  3. After the application is created, go to the application details page. In Function Resources of the Resource Information section, click the function name.

  4. On the page that appears, add the following environment variables. For more information, see Configure environment variables.

    TYPE_IS_ARMS=true
    ARMS_APP_NAME=xxx   # The application name.
    ARMS_REGION_ID=xxx   # The region ID of the Alibaba Cloud account.
    ARMS_LICENSE_KEY=xxx   # The license key.

    2024-10-11_16-31-39

  5. Start the application. Then, you can choose Application Monitoring > Application List and view the configured application in the ARMS console.

    Click the application name. On the Overview page, you can monitor the number of requests, number of errors, average processing time, and other call metrics of the application.

    image.png