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 Go binary file
Run the
wget
command to download the compilation tool based on the region where the environment and machine reside.NoteIf you are able to access Object Storage Service (OSS) over the Internet, you can directly use the public endpoint of the operating system and architecture in the China (Hangzhou) region to obtain the compilation tool.
Grant the compilation tool the permissions required to perform the related operations.
Linux/Darwin
# Grant the permissions. chmod +x instgo
Windows
In Windows, you do not need to grant permissions.
In OpenAPI Explorer, call the DescribeTraceLicenseKey operation to obtain the license key. For more information, see DescribeTraceLicenseKey.
In the directory where the main function of the project is located, run the compilation tool to compile the project. Replace the
{licenseKey}
parameter in the command with the license key obtained in the previous step.If you need to test the compilation result or cannot obtain the license key, add
--dev
to enable Dev Mode. In this mode, you do not need to specify the license key.ImportantThe compilation results in Dev Mode are degraded. Do not use Dev Mode in a production environment.
Run the
./instgo build
command rather than thego build
command.Linux/Darwin
./instgo build --licenseKey="{licenseKey}" --cacheDir=./
Windows
.\instgo.exe build --licenseKey="{licenseKey}" --cacheDir=./
To specify the Linux system as the operating system where Go appliations run in Windows, run the following commands in PowerShell to set compilation environment variables:
$env: GOOS="linux" $env: GOARCH="amd64"
If you want to add additional parameters in the command for subsequent compilation purposes, use a delimiter (
--
) after the options and then add the parameters in the original format. Example:Linux/Darwin
./instgo build --licenseKey="{licenseKey}" --cacheDir=./ -- {arg1} {arg2} ...
Windows
.\instgo.exe build --licenseKey="{licenseKey}" --cacheDir=./ -- {arg1} {arg2} ...
Use the binary file compiled in the previous step to build the image.
References
The following table describes the common Instgo commands.
Command
Flag
Parameter type
Description
Required
build
(compilation)--licenseKey, -l
String
The license key.
Yes (except for Dev Mode)
--dev
-
Specifies Dev Mode as the development mode. In this mode, you can compile data to test functionality without specifying the license key.
ImportantSome features are degraded. Do not use Dev Mode in a production environment.
No
--agentVersion
String
Specifies the version of the ARMS agent.
No
--agentPath
String
Specifies the local path of the ARMS agent.
No
--cacheDir
String
Specifies the cache directory of the ARMS agent.
No
--regionId, -r
String
The ID of the region from which the dependencies of the ARMS agent are downloaded. Default value: cn-hangzhou.
No
--timeout, -t
Integer
The timeout period for downloading the dependencies of the ARMS agent. Unit: seconds. Default value: 180.
No
--verbose, -v
-
Specifies whether to print detailed compilation logs.
No
--vpc
-
Specifies whether to download the dependencies of the ARMS agent over a virtual private cloud (VPC).
No
clean
(cleanup)
-
-
-
-
update
(update)--licenseKey, -l
String
The license key.
Yes
--cacheDir
String
Specifies the cache directory of the ARMS agent.
No
--regionId, -r
String
The ID of the region from which the dependencies of the ARMS agent are downloaded. Default value: cn-hangzhou.
No
--timeout, -t
Integer
The timeout period for downloading the dependencies of the ARMS agent. Unit: seconds. Default value: 180.
No
--vpc
Specifies whether to download the dependencies of the ARMS agent over a VPC.
No
version
(version)
-
-
-
-
The first time that you compile the application, the ARMS agent is downloaded to the
/opt
directory (C:\ProgramData
in Windows) by default. If you have no permissions on the directory, you can use the--cacheDir
flag to specify a cache directory or run thesudo -E
command to compile the agent. In Windows, run commands to compile the application as an administrator.If the compilation is forcibly stopped or killed, a residue may be caused. For information about how to clean up the residue, see Uninstall an ARMS agent for Go.
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
wget
command 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-3.2.2.tgz'
Run the following command to decompress the installation package.
tar xvf ack-onepilot-3.2.2.tgz
Edit 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.accessKey
andaccessKeySecret
: 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 yaml
NoteIf 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-namespace
Run the following command to open the YAML file of the Deployment.
kubectl edit deployment {Deployment name} -o yaml
In the YAML file, go to the
spec.template.metadata
directory 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.