This guide explains how to enable APM Insight monitoring for your Python application running in Docker, using the APM Insight Python agent and Data Exporter (In Same Container).
1. Download the Required Components
- APM Insight Python Agent:
Download python agent
(Extract to get the apm_insight_agent_python directory) - AppManager Data Exporter:
Download Data Exporter
(Download Respective Archive and Extract to get the AppManagerDataExporter directory)
Example: For linux, download and extract AppManagerDataExporter_amd64
2. Add the Agent and Data-Exporter to Your Project
- Place the extracted AppManagerDataExporter_amd64 directory in your project root.
- Place the extracted apm_insight_agent_python/ directory in your project root.
3. Update Your Dockerfile
Add the following steps to your Dockerfile (after your existing Python/app setup).
a). Include Data-Exporter and Agent in docker image
- # Copy exporter directory
- COPY AppManagerDataExporter_amd64/ /opt/AppManagerDataExporter/
- # Copy agent directory
- COPY apm_insight_agent_python/ /opt/apm_insight_agent_python/
- # Switch to agent directory and Install agent Python package
- WORKDIR /opt/apm_insight_agent_python/agent
- RUN pip install .
b). Start the Exporter and Agent with Your App
To ensure both the exporter and the APM Insight agent are running, you need to start both when the container runs.
This is typically done in the Dockerfile’s CMD or ENTRYPOINT.
How to do it?
- The exporter binary should be started in the background.
- The agent should wrap your app’s startup command (using apminsight-run).
Please find the example command to include in your dockerfile below.
- # Entrypoint: Start exporter and agent with your app
- CMD ["sh", "-c", "/opt/AppManagerDataExporter/AppManagerDataExporter/bin/AppManagerDataExporter run & apminsight-run python app.py"]
/opt/AppManagerDataExporter/AppManagerDataExporter/bin/AppManagerDataExporter run => starts the exporter in the background.
apminsight-run python app.py => starts your Python app with the APM Insight agent enabled.
4. Set Environment Variables
Set your license key, app name, and APM server details as environment variables in your Dockerfile or deployment environment
- ENV S247_LICENSE_KEY="{APM_LICENSE_KEY}"
- ENV APM_APP_NAME="{APPLICATION_NAME}"
- ENV APM_HOST="{APM_SERVER_HOST}"
- ENV APM_PORT="{APM_SERVER_PORT}"
5. Build and Run Your Docker Image
6. Verify Monitor Creation
- Check your APM Insight dashboard for data from your app.
- Check container logs for exporter and agent startup messages.
Please find attached the sample dockerfile with changes for exporter and agent included