Help APM APM for Python Install Python Agent

Install APM Insight Python Agent

To install APM Insight Python agent, follow the below given instructions.

Installation instructions

  1. If you are using a virtual environment, activate it and run the following command to install the S247 APMINSIGHT Python package in your virtual environment.

    pip install apminsight
  2. Now you can integrate the Python agent to your application using any of the following methods.
    1. Using the command line
    2. Using the code snippet

    Using the command line

    You need to run your application using the apminsight-run script as shown below. 

    $ apminsight-run <apm-options> <user application execute command> 
    apm-options Description
    ---apm_app_name To add the APM application name
    --apm_log_dir To add a custom log directory for storing APM logs
    --apm_debug To enable debug mode
    --apm_exp_host To configure the S247DataExporter host
    --apm_exp_status_port To configure the S247DataExporter status port
     --apm_exp_data_port To configure the S247DataExporter data port

    Examples: 

    If you want to configure the application name, use the below command:

    apminsight-run --apm_app_name "monitorname"

    If you want to configure the directory location, use the below command:

    apminsight-run --apm_app_name "monitorname" --apm_log_dir "logs location"

    Using the code snippet

    Update the configuration in the code snippet below and place it at the top of your application route file or application start file, then restart your application.

    from apminsight import initialize_agent

        initialize_agent({

            "appname" : "<Your application name>",

     

            '''change if  S247DataExporter is not running in the default ports(20021, 20022):'''

            "exporter_status_port" : "<S247DataExporter status port>",

            "exporter_data_port" : "<S247DataExporter data port>",

     

            '''If you are running S247DataExporter on a separate machine/server or as a Docker container:'''

            "exporter_host" : "<HostName/ContainerName where S247DataExporter is running>"

        })

    For example, for Django applications, add the code snippet at the top of the Django settings.py file. The name of your Django application will be automatically detected by your WSGI_APPLICATION in the application’s settings.py file.

    For Django applications

    For other applications and frameworks, such as Flask, add the code snippet at the top of the application start file.

    code snippet for other applications

    You can also configure the agent using environment variables.

    Configuration Description
    $ export APM_APP_NAME="<Your application name>" To add the application name
    $ export APM_LOGS_DIR="<logs storing path>" To configure the log directory
    $ export APM_EXPORTER_STATUS_PORT=<S247DataExporter status port>,$ export APM_EXPORTER_DATA_PORT=<S247DataExporter data port> To change the S247DataExporter's default running ports (20021, 20022)
    $ APM_EXPORTER_HOST=<HostName/ContainerName where S247DataExporter is running>  To change the host of the S247DataExporter to a different machine or server or as a Docker container
  3. Restart your application.
  4. Perform some transactions so that the agent can collect data.
  5. Log in to your Site24x7 account.
  6. Navigate to APM Insight and click your application to view application metrics.
  7. You can view agent log files in the apminsightdata/logs directory, which will be present in the process-generated location.
    Python agent logs

Was this document helpful?
Thanks for taking the time to share your feedback. We’ll use your feedback to improve our online help resources.

Help APM APM for Python Install Python Agent