For Python applications deployed in ACK clusters, such as web applications built with frameworks like Django, Flask, and FastAPI, or AI and LLM applications developed using LlamaIndex and Langchain, you can use Application Real-Time Monitoring Service (ARMS) to monitor application performance. To enable monitoring, install the ack-onepilot component and modify your Dockerfile. This enables features such as application topology, tracing, API call analysis, anomaly detection, and detailed tracking of large model interactions.
Prerequisites
-
A namespace has been created. For more information, see Manage namespaces and resource quotas. This topic uses
arms-demoas the example namespace. -
The Python runtime is version 3.8 or later.
ARMS is compatible with Python 3.8 and later. Connection issues may occur if you use an earlier version.
-
ARMS is an application performance management (APM) service provided by Alibaba Cloud. For more information about application monitoring, see What is Application Real-Time Monitoring Service (ARMS)? and What is application monitoring?.
Step 1: Install the ack-onepilot component
The legacy arms-pilot component is no longer maintained. You can install the upgraded ack-onepilot component to monitor your applications. ack-onepilot is fully compatible with arms-pilot, which allows you to seamlessly migrate without modifying your application configurations. For more information, see How do I uninstall arms-pilot and install ack-onepilot?.
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, click the name of your cluster. In the left navigation pane, click Components and Add-ons.
-
In the Logs and Monitoring section, find the ack-onepilot add-on and click Install on its card. In the dialog box, configure the parameters and click OK to complete the installation. We recommend that you keep the default values.
NoteMake sure that the version of ack-onepilot is 3.2.4 or later. By default, the ack-onepilot component supports up to 1,000 pods. For every 1,000 pods that exceed this limit, increase the CPU resources for ack-onepilot by 0.5 cores and the memory resources by 512 MB.
After installation, you can upgrade, configure, or uninstall the ack-onepilot add-on on the Add-ons page.
Step 2: Grant permissions to access ARMS resources
-
To monitor applications in an ACK cluster that does not have the
addon.arms.tokensecret, you must manually grant permissions to the cluster to access ARMS resources. If theaddon.arms.tokensecret already exists, you can skip this step.NoteWhen
addon.arms.tokenexists in an ACK cluster, ARMS can automatically complete the password-free authorization process. Typically, ACK managed clusters includeaddon.arms.tokenby default. However, some older ACK managed clusters may be missingaddon.arms.token.-
Check whether the
addon.arms.tokensecret exists. -
If the
addon.arms.tokensecret exists, no further action is required. Otherwise, manually grant permissions to the cluster to access ARMS resources.Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, click the name of your cluster. In the left navigation pane, click Cluster Information.
-
On the Basic Information tab, click the link next to Worker RAM Role in the Cluster Resources section.
-
On the Role page, on the Permissions tab, click Add Permissions.
-
Select the AliyunARMSFullAccess policy and click OK.
-
-
If you want to monitor applications in an ACK managed cluster that is integrated with Elastic Container Instance (ECI), go to the RAM Quick Authorization page to complete the authorization. Then, restart all pods of the ack-onepilot add-on.
Step 3: Integrate the ARMS Python agent into your Dockerfile
Modify your Dockerfile to integrate the ARMS Python agent and use it to start your Python application.
-
Download the agent installer from the PyPI repository.
pip3 install aliyun-bootstrap -
Use aliyun-bootstrap to install the agent.
# The region ID of your Alibaba Cloud account. ARMS_REGION_ID=xxx aliyun-bootstrap -a installNoteTo install a specific version of the Python agent, run the following command:
# Replace ${version} with the actual version number. aliyun-bootstrap -a install -v ${version}For a list of all released Python agent versions, see Release notes of the Python agent.
-
Start the application with the ARMS Python agent.
aliyun-instrument python app.py -
Build the image.
The following code shows a sample Dockerfile before and after modification:
Step 4: Enable ARMS monitoring
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, click the name of your cluster. In the left navigation pane, click .
-
On the Deployments page, find your application and click in the Actions column.
-
In the YAML file, add the following
labelsunderspec.template.metadata.labels: aliyun.com/app-language: python # Required. Specifies the application language as Python. armsPilotAutoEnable: 'on' armsPilotCreateAppName: "deployment-name" # The application's display name in the ARMS console.ImportantIf the version of the ack-onepilot component is 5.0.0 or later, the component automatically downloads and injects the Python agent package when you perform this step. This enables fully non-intrusive monitoring for Python applications, eliminating the need to modify the startup command in the Dockerfile. If you do not want to use this feature, or if you have already installed the Python agent manually in your container, we recommend disabling this feature by adding the following label:
labels: aliyun.com/app-language: python # Required. Specifies the application language as Python. armsPilotAutoEnable: 'on' armsPilotCreateAppName: "deployment-name" # The application's display name in the ARMS console. armsAutoInstrumentationEnable: "off" # Disables non-intrusive agent injection.
The following code provides a complete YAML template to create a Deployment and enable application monitoring:
Step 5: View monitoring details
-
After about one minute, log on to the ARMS console. In the left-side navigation pane, choose to view your Python application and its reported data.
In the application list, you can see the connected arms-python-client application and its metrics, such as requests per second, error rate, and average response time.
-
Click the Name to go to the application monitoring page in the ARMS console and view detailed monitoring information. For more information, see Application overview.
(Optional) Step 6: Release resources
If you no longer need to monitor your Python application with ARMS, you can uninstall the ARMS Python agent to stop monitoring. For more information, see Uninstall the Python agent.
> Edit YAML