AppDynamics Python Agent helps you monitor the OpenAI API usage and related metrics. It monitors the ChatCompletion and Completion type requests created using the openai-python framework to the OpenAI backend.

Python Agent supports OpenAI <= 0.28.1.


The following metrics are reported at the application, tier, and node levels:

  • Calls per minute
  • Cost
  • Errors per minute
  • Tokens

The following are the example metric paths:

  • Per model metric path - Application Infrastructure Performance|OpenAI_Tier|OpenAI|ada|Cost
  • All model cumulative metrics path - Application Infrastructure Performance|OpenAI_Tier|OpenAI|Cost - All Models
  • Net application level metrics path - Overall Application Summary|OpenAI - Cost - ada


These metrics are reported even if the exit call is outside the business transaction. However, the Average Response Time(ms) metric is not reported when the exit call is outside the business transaction.

Prerequisites

Ensure that you meet the following prerequisites to monitor the OpenAI API exit calls with AppDynamics:

Create a Custom Dashboard

  1. Download Custom_Dashboard_v1.0.zip. It contains the following four files:

    FilenameDescription
    template_app.jsonThe template to create the application-level dashboard.
    template_tier.jsonThe template to create the tier-level dashboard.
    main.pyPython script to create the dashboards.
    readme.mdDescription of the solution.


  2. Run the following command:

    cd Custom_dashboard_script
    python3 main.py
    CODE

    The preceding command prompts you to specify the dashboard type (application or tier) that you want to create.

  3. Based on your selected dashboard type, you will be prompted to specify the following dashboard details.

    VariableDescriptionDefaultPossible ValuesRequired
    Application NameThe application created in the Controller with OpenAI monitoring enabled.noneopenai_app_1Yes
    OpenAI Endpoints Host NameThe hostname of the OpenAI backend.
    api.openai.com
    api.openai.com
    Optional
    OpenAI Endpoints PortThe port of the OpenAI backend.443443Optional
    Dashboard NameThe dashboard name to be displayed on Dashboard & Reports in the Controller UI.openai_app_dashboardopenai_app_dashboardOptional
    Output File NameThe output dashboard .json filename.app_dashboard.jsonapp_dashboard.jsonOptional
    VariableDescriptionDefaultPossible ValuesRequired
    Application NameThe application created in the Controller with OpenAI monitoring enabled.noneopenai_app_1Yes
    Tier NameName of the Tier exposed to OpenAI backend calls.noneopenai_tier_1Yes
    Business Transaction NameThe name of the business transaction reported to the host.openai_tier_bt_nameopenai_btOptional
    OpenAI Endpoints Host NameThe hostname of the OpenAI backend.
    api.openai.com
    api.openai.com
    Optional
    OpenAI Endpoints PortThe port of the OpenAI backend.443443Optional
    Dashboard NameThe dashboard name to be displayed on Dashboard & Reports in the Controller UI.openai_tier_dashboardopenai_tier_dashboardOptional
    Output File NameThe output dashboard .json filename.tier_dashboard.jsontier_dashboard.jsonOptional


  4. Import the dashboard in the Controller UI. See Create and Manage Custom Dashboards and Templates.