APM Insight Python Agent – Offline Installation via Environment Variables

APM Insight Python Agent – Offline Installation via Environment Variables

This article explains how to install the APM Insight Python Agent in offline (air-gapped) environments using environment variables. No code changes or pip install required.

Refer: APM Insight Python Agent – Official Installation Help


1. Prerequisites
Requirement Details How to Verify
Python 3.5+ Python 2.x is not supported python --version
Correct Architecture ZIP amd64 / arm64 / 386 — must match server architecture Check OS system information
AppManager Data Exporter Must be installed and running (ports 20021 & 20022) Confirm ports 20021 and 20022 are listening
Read/Write Permissions Application user must have access to the agent directory Verify directory permissions for the app user
2. Offline Installation Steps

Step 1 — Download & transfer the agent ZIP

From Applications Manager: APM → Add New Monitor → Python → Download Agent

Transfer apm_insight_agent_python.zip to the target server using any available method (SCP, shared folder, USB, etc.) and place it in a working directory.

Example: <AGENT_HOME>/ (e.g., /opt/apminsight/ or C:\apminsight\)


Step 2 — Verify checksum (recommended)

Generate the SHA256 hash of the downloaded ZIP and compare it with the .sha256 file bundled alongside the agent. Both values must match to confirm file integrity.

For detailed checksum validation steps, refer: APM Insight Python Agent – Checksum Validation


Step 3 — Extract the agent

Create a directory (e.g., <AGENT_HOME>) and extract the ZIP contents into a subfolder named apminsight_agent.

Use your OS's built-in extraction tool — right-click → Extract, or a command-line utility:

unzip apm_insight_agent_python.zip -d apminsight_agent     # Linux / macOS
Expand-Archive apm_insight_agent_python.zip -DestinationPath apminsight_agent   # Windows PowerShell

After extraction, the directory structure should look like:

<AGENT_HOME>/apminsight_agent/
wheels/
apminsight/
bootstrap/
sitecustomize.py ← agent bootstrap entry point
...
...

Step 4 — Set environment variables and start your application

Set the following environment variables before starting your Python application. Use the appropriate syntax for your OS/shell:

Variable Value
PYTHONPATH <AGENT_HOME>/apminsight_agent/wheels/apminsight/bootstrap + <AGENT_HOME>/apminsight_agent/wheels
use : as separator on Linux/macOS, ; on Windows
S247_LICENSE_KEY Your license key from APM → Agent Download page
APM_APP_NAME Application display name for the APM monitor
APM_LOGS_DIR (optional) Custom directory for agent logs (default: application working directory)
APM_EXPORTER_HOST (optional) Hostname or container name where the Data Exporter is running (default: localhost). Set this when the Data Exporter runs on a different machine, server, or Docker container.
APM_EXPORTER_STATUS_PORT (optional) Data Exporter status port (default: 20021). Set only if the default port has been changed.
APM_EXPORTER_DATA_PORT (optional) Data Exporter data port (default: 20022). Set only if the default port has been changed.

Example (Linux / macOS — Bash):

export PYTHONPATH="<AGENT_HOME>/apminsight_agent/wheels/apminsight/bootstrap:<AGENT_HOME>/apminsight_agent/wheels"
export S247_LICENSE_KEY="<YOUR_LICENSE_KEY>"
export APM_APP_NAME="<YOUR_APP_NAME>"

# (Optional) If Data Exporter is on a different host or non-default ports
export APM_EXPORTER_HOST="localhost" # default: localhost
export APM_EXPORTER_STATUS_PORT="20021" # default: 20021
export APM_EXPORTER_DATA_PORT="20022" # default: 20022

python app.py

Example (Windows — Command Prompt):

set PYTHONPATH="<AGENT_HOME>\apminsight_agent\wheels\apminsight\bootstrap;<AGENT_HOME>\apminsight_agent\wheels"
set S247_LICENSE_KEY="<YOUR_LICENSE_KEY>"
set APM_APP_NAME="<YOUR_APP_NAME>"

REM (Optional) If Data Exporter is on a different host or non-default ports
set APM_EXPORTER_HOST="localhost" REM default: localhost
set APM_EXPORTER_STATUS_PORT="20021" REM default: 20021
set APM_EXPORTER_DATA_PORT="20022" REM default: 20022

python app.py
How it works: Python auto-loads sitecustomize.py from PYTHONPATH. The agent's bootstrap sitecustomize.py initialises the APM Insight agent automatically — no code changes needed.

Tip — Persist environment variables: To ensure variables survive restarts, configure them in your OS/service manager:
  • systemd — add Environment="VARIABLE=value" entries in the [Service] section of your unit file
  • Windows Services — set system environment variables via System Properties → Environment Variables
  • Docker — use -e flags or an env_file
  • Supervisor / PM2 — configure in the respective process config file
3. Environment Variable Reference
Variable Required Description Default
PYTHONPATH Yes Must include bootstrap/ and wheels/ paths
S247_LICENSE_KEY Yes License key / device key from APM tab
APM_APP_NAME Yes Monitor display name in APM tab
APM_LOGS_DIR No Custom agent log directory App working dir
APM_EXPORTER_HOST No Data Exporter hostname (if not on same host) localhost
APM_EXPORTER_STATUS_PORT No Exporter status port 20021
APM_EXPORTER_DATA_PORT No Exporter data port 20022
4. Verification

1. Check startup output — you should see:

APM Insight agent initialized successfully

2. Check agent log

Open the log file at apminsightdata/logs/apminsight-agent-log.txt (relative to the application working directory).

Look for lines like INFO flask instrumented, INFO werkzeug.serving instrumented, etc.

3. Verify agent version (offline agent won’t appear in pip list)

Quotepython -c "import apminsight; print(apminsight.name, apminsight.version)"
5. Troubleshooting
Issue Cause Resolution
ModuleNotFoundError: No module named 'apminsight' PYTHONPATH missing wheels/ directory Ensure PYTHONPATH includes <AGENT_HOME>/apminsight_agent/wheels
Socket Connection failed Data Exporter not running on ports 20021/20022 Start the AppManager Data Exporter service and confirm ports 20021 & 20022 are listening
Please configure a valid license key S247_LICENSE_KEY not set or invalid Set the S247_LICENSE_KEY environment variable with the correct license key from the APM tab
Agent not in pip list Expected — offline agent is loaded via PYTHONPATH, not pip Use python -c "import apminsight; print(apminsight.version)" to verify
Agent loads when not intended PYTHONPATH persists in shell/profile Remove or unset the PYTHONPATH variable from the current session and any startup profiles

Data to collect when contacting support:
  1. apminsightdata/logs/apminsight-agent-log.txt
  2. apminsightdata/apminsight_info.ini
  3. Application startup output
  4. Current PYTHONPATH value, Python version, and OS details

                  New to ADSelfService Plus?

                    • Related Articles

                    • How to add an APM Insight Python agent in Kubernetes via InitContainers?

                      Adding the APM Insight Python agent via init containers in Kubernetes enables the seamless integration of performance monitoring for Python applications, ensuring efficient tracking and analysis of application behavior within the Kubernetes ...
                    • APM Insight Python Agent & Data Exporter Onboarding Docker Guide (Same Container)

                      Overview 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: ...
                    • Uninstrumented Block of Code - APM Insight

                      In the traces tab --> Slowest Method Calls and Count we show if you find Un-instrumented block of code the reason is as follows: Basically, What is un-instrumented block of code in APM Insight? By default, APM Insight agent monitors known frameworks ...
                    • Self monitor Applications Manager using APM Insight Java Agent

                      Applications Manager is built with Java, hence we can monitor it using APM Insight Java Agent to measure it's performance continuously, which can be very much useful. Setting up APM Insight Java Agent Follow the below steps to download and set up the ...
                    • Adding APM Insight Java agent in a Kubernetes environment

                      There are three methods for installing the APM Insight Java agent in a Kubernetes environment: Using Dockerfile Using InitContainers Using Persistent Volumes Prerequisites Download the latest APM Insight Java agent ZIP file. Extract the ZIP file and ...