mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 19:24:27 +00:00
(v0) prometheus metric
This commit is contained in:
parent
358f94a4c3
commit
4b7e102187
1 changed files with 36 additions and 0 deletions
|
@ -983,6 +983,42 @@ def cost_tracking():
|
|||
litellm.success_callback.append(_PROXY_track_cost_callback) # type: ignore
|
||||
|
||||
|
||||
from prometheus_client import Counter, REGISTRY
|
||||
from prometheus_client import make_asgi_app
|
||||
|
||||
# Add prometheus asgi middleware to route /metrics requests
|
||||
metrics_app = make_asgi_app()
|
||||
app.mount("/metrics", metrics_app)
|
||||
try:
|
||||
calls_metric = Counter("calls_metric", "Measure of calls")
|
||||
tokens_metric = Counter("tokens_metric", "Measure of tokens")
|
||||
spend_metric = Counter("spend_metric", "Measure of spend")
|
||||
except:
|
||||
pass
|
||||
|
||||
# # Define Prometheus counters for metrics
|
||||
# Register metrics with the default registry
|
||||
|
||||
|
||||
def track_prometheus_metrics(
|
||||
kwargs, # kwargs to completion
|
||||
completion_response, # response from completion
|
||||
start_time,
|
||||
end_time, # start/end time
|
||||
):
|
||||
global calls_metric
|
||||
user: str = ("issues",)
|
||||
key: str = ("sk-02Wr4IAlN3NvPXvL5JVvDA",)
|
||||
model: str = ("gpt-3.5-turbo",)
|
||||
budgets = 1
|
||||
tokens = 20
|
||||
# print("incrementing prometheus metrics")
|
||||
calls_metric.labels(user, key, model).inc()
|
||||
|
||||
|
||||
litellm.callbacks.append(track_prometheus_metrics)
|
||||
|
||||
|
||||
async def _PROXY_track_cost_callback(
|
||||
kwargs, # kwargs to completion
|
||||
completion_response: litellm.ModelResponse, # response from completion
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue