To get started, follow these steps:
- Create an index named
open_ai
in your Splunk instance. - Set up Splunk's HTTP Event Collector (HEC) and configure it to use the
open_ai
index with a_json
sourcetype. - Set the following environmental variables:
SPLUNK_HEC_URL
(e.g., https://localhost:8088/services/collector)SPLUNK_HEC_TOKEN
OPENAI_API_KEY
- Install the necessary libraries by running the command:
pip3 install openai requests
. - Add the
openai_splunk_monitor.py
file to your project and import theinit_monitor()
function from it. Refer to the providedexample.py
for guidance.
The calculation of the funds spent is performed in Splunk. For that create a lookup based on the attached openai_prices.csv
and name it openai_prices
.
You can change the price values if they are updated. Prices are based on https://openai.com/pricing.
Create a new dashboard in Dashboard Studio and add the code from dashboard.json
.
Monkey patching is a technique utilized to alter the behavior of the Completion
call dynamically during runtime.
This modification allows for the capture of response and metrics, which can then be sent to Splunk.
The openai-splunk-monitoring
project is governed by the MIT License.
Additionally, it includes source code from external libraries.
For a comprehensive list of these libraries and the corresponding licensing terms, please refer to the third-party notices document.
Find more detail here: https://pelekh-o.github.io/blog/post/monitoring-openai-api-with-splunk/