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
Use the ARMS agent for Go to compile the Go application. For more information, see Step 1: Compile the Go binary file.
Upload the compiled Go binary file to Function Compute. For more information, see Create an event function.
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.
Run the function. Then, you can choose ARMS console.
and view the configured application in theClick 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.
Method 2: Build a Go application in Function Compute
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
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.
After the application is created, go to the application details page. In Function Resources of the
section, click the function name.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.
Start the application. Then, you can choose ARMS console.
and view the configured application in theClick 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.