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 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. ...
    • No data for service and process in Windows server monitor

      If you see "No Data" for process and service metrics (such as CPU or memory usage of monitored services) in the Site24x7 Windows server monitor user interface, follow the troubleshooting steps below. Run PowerShell Commands Open PowerShell as ...
    • Add Node.js agent in Kubernetes via InitContainers (using prebuilt agent image)

      To integrate the APM Insight Node.js agent into your Kubernetes applications using InitContainers, follow the steps given below: Step 1: Create an empty volume that will be used to copy the agent files during the initContainers process. Example: ...
    • How to uninstall the Site24x7 Windows Server Monitoring Agent

      Method 1: To uninstall the Site24x7 Windows Server Monitoring Agent, click the link below: https://staticdownloads.site24x7.com/server/Site24x7WindowsAgentUninstall.zip Unzip and execute the Uninstall.bat file in the Command Prompt as an ...
    • Bundled .NET and .NET Core agents in a single MSI

      In APM Insight .NET agent version 6.8.0, the .NET and .NET Core agents have been bundled into a single MSI, enabling unified monitoring of both application types. Upgrade requirements for .NET Core agent 6.7 and below If you're using .NET Core agent ...