After you install an Application Real-Time Monitoring Service (ARMS) agent for a Python application, ARMS starts to monitor the application. Then, you can view the monitoring data of the application, such as the topology, traces, and SQL analysis. This topic describes how to manually install an ARMS agent for a Python application.
For applications deployed in Container Service for Kubernetes (ACK) clusters, we recommend that you install the ack-onepilot component rather than manually install an ARMS agent.
If you have any questions when you use an ARMS agent, join the DingTalk group chat (ID: 35568145) to obtain technical support.
Before you begin
Make sure the environment where the application resides is connected to Alibaba Cloud over the Internet or an internal network, and the security group of the environment allows outbound traffic for TCP ports 80 and 443.
Check the versions of Python and frameworks. For more information, see Compatibility requirements of the ARMS agent for Python.
Usage notes
If you need to use Gunicorn for application startup, change unicorn to gunicorn in the command.
Use Unicorn:
unicorn -w 4 -b 0.0.0.0:8000 app:app
Use Gunicorn:
gunicorn -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000 app:app
If Gevent is used, set the
GEVENT_ENABLE
environment variable totrue
.Assuming that your application contains the following code:
from gevent import monkey monkey.patch_all()
Set the
GEVENT_ENABLE
environment variable totrue
:GEVENT_ENABLE=true
Step 1: Download and install the agent
Download the agent installer from the Python Package Index (PyPI) repository.
pip3 install aliyun-bootstrap
Install the ARMS agent for Python using aliyun-bootstrap.
aliyun-bootstrap -a install
Step 2: Configure environment variables
Manually add the following environment variables to the Python application.
export ARMS_APP_NAME=xxx # The name of the application.
export ARMS_REGION_ID=xxx # The region ID.
export ARMS_LICENSE_KEY=xxx # The license key.
export ARMS_IS_PUBLIC=True
You can obtain the license key by calling an API operation. For more information, see DescribeTraceLicenseKey.
(Optional) Sample Dockerfile
For the Docker environment, you can refer to the following sample Dockerfile to install an ARMS agent.
# Add environment variables.
ENV ARMS_APP_NAME={AppName}
ENV ARMS_REGION_ID={regionId}
ENV ARMS_LICENSE_KEY={licenseKey}
## Original environment
Step 3: Start the application
If you start the application by using the ARMS agent for Python, run the following command:
aliyun-instrument python app.py
(Optional) If you start the application by importing the agent for Python in the main entry file of the application, such as
main.py/app.py
, run the following command:
from aliyun.opentelemetry.instrumentation.auto_instrumentation import sitecustomize
Verify 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.