Skip to content

Commit

Permalink
improve metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
extreme4all committed Nov 22, 2024
1 parent 98d7a28 commit 4326cb2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/core/fastapi/middleware/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ async def dispatch(self, request: Request, call_next):

# Calculate request latency
latency = time.time() - start_time
endpoint = request.url.path

# Update Prometheus metrics
REQUEST_COUNT.labels(
method=request.method, endpoint=endpoint, http_status=response.status_code
method=request.method,
endpoint=request.url.path,
http_status=response.status_code,
).inc()
REQUEST_LATENCY.labels(endpoint=endpoint).observe(latency)
REQUEST_LATENCY.labels(
method=request.method,
endpoint=request.url.path,
).observe(latency)

return response

0 comments on commit 4326cb2

Please sign in to comment.