mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 11:43:54 +00:00
prometheus - safe update start / end time
This commit is contained in:
parent
e084f14a47
commit
fddf10eeb8
1 changed files with 11 additions and 7 deletions
|
@ -349,19 +349,23 @@ class PrometheusLogger(CustomLogger):
|
|||
# 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_start_time = kwargs.get("api_call_start_time", None)
|
||||
|
||||
if api_call_start_time is not None and isinstance(
|
||||
api_call_start_time, datetime
|
||||
):
|
||||
api_call_total_time: timedelta = (
|
||||
kwargs.get("end_time") - api_call_start_time
|
||||
)
|
||||
api_call_total_time_seconds = api_call_total_time.total_seconds()
|
||||
self.litellm_llm_api_latency_metric.labels(model).observe(
|
||||
api_call_total_time_seconds
|
||||
)
|
||||
|
||||
# log metrics
|
||||
self.litellm_request_total_latency_metric.labels(model).observe(
|
||||
total_time_seconds
|
||||
)
|
||||
self.litellm_llm_api_latency_metric.labels(model).observe(
|
||||
api_call_total_time_seconds
|
||||
)
|
||||
|
||||
# set x-ratelimit headers
|
||||
if premium_user is True:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue