Add Python agent to a Python application service

Adding a Python agent to a Python application service

To monitor a Python application using Site24x7 APM, you need to integrate the Site24x7 Python agent as a system service. Follow the steps below to install the S24x7DataExporter, add the agent to a custom directory, and configure the environment.
Note: Ensure all prerequisites are met before installing the Python agent.

Step 1: Install the S247DataExporter

If the S24x7DataExporter is not already installed, follow these steps:
  1. Download the installation script.
  2.         
        wget -O InstallDataExporter.sh
        https://staticdownloads.site24x7.com/apminsight/S247DataExporter/linux/InstallDataExporter.sh
                
  3. Execute the script with your Site24x7 license key.
  4.     
        sudo sh InstallDataExporter.sh -license.key "your_device_key"
        
Notes
Note: Replace "your_device_key" with your account's unique license key. You can get it from your Site24x7 account by navigating to Admin > Developer > Device Key.

Step 2: Install the Python agent in a custom directory

  1. Install the Site24x7 Python agent using the --target option:
  2.                 
        pip install apminsight --target /custom/path
        
  3. Verify the installation:
  4.     pip show apminsight
        

Step 3: Add environment variables to the system service file

In your systemd service file (e.g., /etc/systemd/system/your-app.service), insert the following Environment line before the ExecStart directive.
    
    Environment="S247_LICENSE_KEY=your_device_key" "APM_APP_NAME=your_app_name" "PYTHONPATH=/custom/path/apminsight:/custom/path/apminsight/bootstrap"
    ExecStart=/usr/bin/python3 /path/to/your/flask/app/app.py
            

Notes
Note: 
1. Replace your_device_key with the unique license key (see step 1).
2. Replace your_app_name with the custom name for your application monitor as it will appear in the Site24x7 portal.
3. Ensure custom/path matches the directory used during agent installation in step 2.

Step 4: Start the application service

  1. Reload systemd and start your Python application service to activate the installed agent.
  2. Trigger a few transactions in your Python application to initiate data collection. 
Once the service is running and transactions are triggered, the Python agent will begin sending telemetry data to Site24x7. You can then view the metrics in the Site24x7 > APM > Applications section.

An example systemd service file
    
    [Unit]
    Description=Flask Application
    After=network.target

    [Service]
    User=your-username
    Group=your-username
    WorkingDirectory=/custom/path
    Environment="S247_LICENSE_KEY=your_device_key" "APM_APP_NAME=your_app_name" "PYTHONPATH=/home/apminsight:/home/apminsight/bootstrap"
    ExecStart=/usr/bin/python3 /path/to/your/flask/app/app.py
    Restart=always

    [Install]
    WantedBy=multi-user.target
    • Related Articles

    • Prerequisites for Python agent installation

      For a smooth Python agent installation, ensure that you've fulfilled the following prerequisites: The environment should support Python version 3.7 or above. The application should be built on any of the supported frameworks. The application user ...
    • Prerequisites for Java agent installation

      For a smooth Java agent installation, ensure that you've fulfilled the following prerequisites. The environment should have Java version 8 or above installed. The application user should have full permissions over the agent directory. The server ...
    • Prerequisites for Node.js agent installation

      For a smooth Node.js agent installation, ensure that you've fulfilled the following prerequisites. The environment should have node version 16.20.2 or above installed. The application user should have full permission to access the agent directory. ...
    • How to set the PHP path during agent installation?

      This is only applicable to the agent versions 4.2 and above. For Linux Step 1: Download the installation script. wget -O InstallAgentPHP.sh https://staticdownloads.site24x7.com/apminsight/agents/AgentPHP/linux/InstallAgentPHP.sh Step 2: Set your PHP ...
    • APM Insight .NET agent bulk installation using ManageEngine Endpoint Central

      You can install the APM Insight .NET agent on multiple machines at once by following the steps given below: Download the APM Insight .NET agent from the Site24x7 account. Log in to the ManageEngine Endpoint Central portal and click the Software ...