Prerequisites and installation of S247DataExporter and Python agent in a Docker container
Step 1: Check prerequisites
- Before installing the Python agent, verify that all prerequisites are met.
- To install the required system utilities for the S247DataExporter in your Docker container, add the following command to your Dockerfile:
- RUN apt-get update && apt-get install -y wget unzip procps curl
Step 2: Set agent configuration via environment variables
Configure the Python agent and the S247DataExporter using the following environment variables in your Dockerfile:
- # Mandatory
- ENV S247_LICENSE_KEY="Your Site24x7 device key"
- ENV APM_APP_NAME="Your application name"
- # Optional
- ENV AGENT_STATUS_PORT=20021
- ENV AGENT_DATA_PORT=20022
Where:
- S247_LICENSE_KEY: Your unique Site24x7 device key used to authenticate and link the agent with your account.
- APM_APP_NAME: A custom name for your application monitor as it will appear in the Site24x7 portal.
- AGENT_STATUS_PORT (optional): A port for agent status checks. The default value is 20021.
- AGENT_DATA_PORT (optional): A port used for internal agent communication and data handling. The default value is 20022.
Step 3: Install the S247DataExporter
Add the following commands to your Dockerfile to download and install the
S247DataExporter:
If the Docker container is running as a user other than root, you need to provide permission for that user to run the exporter:
- chmod -R 777 /opt/S247DataExporter
Step 4: Install the Python agent
Install the APM Insight Python agent using pip:
- RUN pip3 install -U apminsight
Step 5: Start your application with the Python agent and the exporter
Method 1: Modify the CMD directly in the Dockerfile
In this method, you update the Dockerfile's CMD to perform the following steps:
- Start the S247DataExporter service.
- Launch your Python application using the apminsight-run command, which enables APM Insight monitoring.
For example, if your original CMD was:
- CMD ["gunicorn", "-w", "4", "app:wsgi"]
You would modify it to:
- CMD ["sh", "-c", "/opt/S247DataExporter/bin/service.sh start && apminsight-run gunicorn -w 4 app:wsgi"]
This ensures both the S247DataExporter and Python agent are started automatically when the container launches.
Method 2: Use a custom entrypoint script
Create a script (example-entrypoint.sh) and copy it into the container:
example-entrypoint.sh
- #!/bin/sh
- # Start the S247DataExporter service
- sh /opt/S247DataExporter/bin/service.sh start
- # Start your Python application using apminsight-run
- apminsight-run <your app start command>
- Replace <your app start command> with the actual command to run your Python app: gunicorn -w 4 app:wsgi
- This script is then copied into the container and used as the Docker entrypoint.
In your Dockerfile:
- COPY ./example-entrypoint.sh /example-entrypoint.sh
- ENTRYPOINT [ "sh", "/example-entrypoint.sh" ]