You can use the Application Monitoring sub-service of Application Real-Time Monitoring Service (ARMS) to monitor Go applications that are deployed in Kubernetes clusters. ARMS allows you to monitor applications based on various performance metrics, such as the topology, API requests, abnormal transactions, slow transactions, and SQL analysis. This topic describes how to automatically install an ARMS agent for Go in a Kubernetes cluster.
This topic does not apply to Alibaba Cloud Container Service for Kubernetes (ACK) clusters. For information about how to install an ARMS agent for Go in an ACK cluster, see Automatically install an ARMS agent in ACK.
Prerequisites
The kube-apiserver version of the Kubernetes cluster is 1.10 or later.
The cluster is accessible over the Internet, or a network connection is established between an Alibaba Cloud virtual private cloud (VPC) and the cluster by using a Cloud Enterprise Network (CEN) instance.
The application uses Go 1.18 or later.
Step 1: Compile the Golang application image
(Optional) If your project uses vendor mode for compilation or the compile-time parameters include
-mod=vendor, check the following:Check if the go.mod file contains the `google.golang.org/protobuf` dependency, either directly or indirectly. If not, see the following instructions:
Check if the compile-time parameters include
-mod=vendor. If not, add-mod=vendoraftergo build.
Use the
wgetcommand to download the compile-time tool instgo. Select the download address based on your compile-time environment and machine region.Note that instgo automatically updates at compile-time. Save instgo in a folder where you have modification permissions.
NoteInstgo is a compile-time tool provided by ARMS for Go applications. After you compile your Go project with instgo, ARMS can monitor your application.
The compile-time tool is the same for all regions. If your environment can access Object Storage Service (OSS) over the internet, you can use the internet download address for China (Hangzhou) for your operating system and architecture.
Grant executable permissions to the compile-time tool.
Linux/Mac
# Grant executable permissions chmod +x instgoWindows
No executable permissions are required for Windows.
Obtain the LicenseKey and configure compile-time parameters.
ImportantIf you skip this step, instgo enters dev mode and installs the latest version of the ARMS agent by default. To deploy your application in a production environment, you must configure the following parameters.
Obtain the LicenseKey by calling the DescribeTraceLicenseKey OpenAPI operation.
On the DescribeTraceLicenseKey page, click Debug. Select a region and click Initiate Call to obtain the LicenseKey.

After you obtain the LicenseKey, use the
setcommand to configure the compile-time parameters.instgo set --licenseKey=${YourLicenseKey}
Add `instgo` as a prefix to your original compile command and run the command.
instgo go build {arg1} {arg2} {arg3}If you use `go install` to compile the project, you can also add `instgo` as a prefix to the command.
Build the image using the binary file compiled in the previous step.
Step 2: Install Helm V3
Step 3: Install an ARMS agent for Go
You can use Application Monitoring to monitor the following types of applications: Deployment and StatefulSet. This section uses a Deployment as an example.
Run the following
wgetcommand to download the installation package of the ARMS agent for Go (ack-onepilot).wget 'https://aliacs-app-catalog.oss-cn-hangzhou.aliyuncs.com/charts-incubator/ack-onepilot-5.1.1.tgz'Run the following command to decompress the installation package.
tar xvf ack-onepilot-5.1.1.tgzEdit the values.yaml file in the installation package. Modify the following parameters based on your business requirements and save the file.
registry: registry-__ACK_REGION_ID__.ack.aliyuncs.com/acs/ cluster_id: __ACK_CLUSTER_ID__ accessKey: __ACCESSKEY__ accessKeySecret: __ACCESSKEY_SECRET__ uid: "__ACK_UID__" region_id: __ACK_REGION_ID__registry: the image address of ack-onepilot.cluster_id: the unique ID of the Kubernetes cluster. We recommend that you specify this parameter in the<uid>-<clusterid>format.accessKeyandaccessKeySecret: the AccessKey ID and AccessKey secret of your Alibaba Cloud account. For more information about how to obtain an AccessKey pair, see Create an AccessKey pair.ImportantYou must make sure that the AliyunARMSFullAccess and AliyunSTSAssumeRoleAccess policies are attached to your Alibaba Cloud account.
uid: the ID of your Alibaba Cloud account. To obtain the ID of your Alibaba Cloud account, move the pointer over the profile picture in the upper-right corner of the Alibaba Cloud Management Console.region_id: the region ID. For more information about the regions that support Application Monitoring, see Supported regions.
Install ack-onepilot.
Run the following command without opening the installation package.
helm3 upgrade --install ack-onepilot ack-onepilot --namespace ack-onepilot --create-namespace
Step 4: Modify the YAML file of the application
Run the following command to view the YAML file of the Deployment.
kubectl get deployment {Deployment name} -o yamlNoteIf you do not know the Deployment name, run the following command to view all Deployments. You can find the Deployment in the results. Then, view the YAML file of the application.
kubectl get deployments --all-namespaceRun the following command to open the YAML file of the Deployment.
kubectl edit deployment {Deployment name} -o yamlIn the YAML file, go to the
spec.template.metadatadirectory and add the following content.labels: aliyun.com/app-language: "golang" # The value indicates that the application uses the Go language. armsPilotAutoEnable: "on" armsPilotCreateAppName: "<your-deployment-name>" # Replace <your-deployment-name> with the Deployment name.The following example shows a complete YAML file for creating and monitoring a Deployment in a Kubernetes cluster.
Check the result
After about one minute, log on to the ARMS console. In the left-side navigation pane, choose . If the application is displayed on the Application List page, the application is being monitored.
