mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-28 04:04:31 +00:00
track litellm_request_latency_metric
This commit is contained in:
parent
8162208a5c
commit
c719c375f7
2 changed files with 41 additions and 1 deletions
|
@ -60,6 +60,25 @@ class PrometheusLogger(CustomLogger):
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# request latency metrics
|
||||||
|
self.litellm_request_latency_metric = Histogram(
|
||||||
|
"litellm_request_latency_metric",
|
||||||
|
"Total latency (seconds) for a request to LiteLLM",
|
||||||
|
labelnames=[
|
||||||
|
"model",
|
||||||
|
"litellm_call_id",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
self.litellm_deployment_latency_metric = Histogram(
|
||||||
|
"litellm_deployment_latency_metric",
|
||||||
|
"Total latency (seconds) for a models LLM API call",
|
||||||
|
labelnames=[
|
||||||
|
"model",
|
||||||
|
"litellm_call_id",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
# Counter for spend
|
# Counter for spend
|
||||||
self.litellm_spend_metric = Counter(
|
self.litellm_spend_metric = Counter(
|
||||||
"litellm_spend_metric",
|
"litellm_spend_metric",
|
||||||
|
@ -329,6 +348,25 @@ class PrometheusLogger(CustomLogger):
|
||||||
user_api_key, user_api_key_alias, model_group
|
user_api_key, user_api_key_alias, model_group
|
||||||
).set(remaining_tokens)
|
).set(remaining_tokens)
|
||||||
|
|
||||||
|
# latency metrics
|
||||||
|
total_time: timedelta = kwargs.get("end_time") - kwargs.get("start_time")
|
||||||
|
total_time_seconds = total_time.total_seconds()
|
||||||
|
api_call_total_time: timedelta = kwargs.get("end_time") - kwargs.get(
|
||||||
|
"api_call_start_time"
|
||||||
|
)
|
||||||
|
|
||||||
|
api_call_total_time_seconds = api_call_total_time.total_seconds()
|
||||||
|
|
||||||
|
litellm_call_id = kwargs.get("litellm_call_id")
|
||||||
|
|
||||||
|
self.litellm_request_latency_metric.labels(model, litellm_call_id).observe(
|
||||||
|
total_time_seconds
|
||||||
|
)
|
||||||
|
|
||||||
|
self.litellm_deployment_latency_metric.labels(model, litellm_call_id).observe(
|
||||||
|
api_call_total_time_seconds
|
||||||
|
)
|
||||||
|
|
||||||
# set x-ratelimit headers
|
# set x-ratelimit headers
|
||||||
if premium_user is True:
|
if premium_user is True:
|
||||||
self.set_llm_deployment_success_metrics(
|
self.set_llm_deployment_success_metrics(
|
||||||
|
|
|
@ -4,7 +4,9 @@ model_list:
|
||||||
model: openai/fake
|
model: openai/fake
|
||||||
api_key: fake-key
|
api_key: fake-key
|
||||||
api_base: https://exampleopenaiendpoint-production.up.railway.app/
|
api_base: https://exampleopenaiendpoint-production.up.railway.app/
|
||||||
|
litellm_settings:
|
||||||
|
success_callback: ["prometheus"]
|
||||||
|
failure_callback: ["prometheus"]
|
||||||
guardrails:
|
guardrails:
|
||||||
- guardrail_name: "lakera-pre-guard"
|
- guardrail_name: "lakera-pre-guard"
|
||||||
litellm_params:
|
litellm_params:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue