litellm/docs/my-website/docs
ohadgur 0bb26c3f1b
feat(proxy): add Prisma DB pool and engine health metrics to Prometheus (#22655)
* feat(proxy): add Prisma DB pool and engine health metrics to Prometheus

Add a PrismaMetricsCollector that periodically queries pg_stat_activity
and the Prisma engine process to expose connection pool and engine health
as Prometheus gauges/counters. Auto-enabled when prometheus_system is in
service_callback.

New metrics:
- litellm_db_pool_active_connections (Gauge)
- litellm_db_pool_idle_connections (Gauge)
- litellm_db_pool_total_connections (Gauge)
- litellm_db_pool_waiting_connections (Gauge)
- litellm_db_engine_up (Gauge)
- litellm_db_engine_restarts_total (Counter)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: address Greptile review feedback

- Only increment engine_restarts counter on heavy reconnects (engine
  actually dead), not lightweight network-blip reconnects
- Fix potential KeyError in _get_or_create_gauge/counter fallback path
  when REGISTRY._names_to_collectors is absent
- Rename litellm_db_pool_waiting_connections to
  litellm_db_pool_lock_waiting_connections to clarify it measures lock
  contention, not pool slot queuing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: warn when prometheus_system enabled but watchdog disabled

Log a warning when users have prometheus_system in service_callback
but PRISMA_HEALTH_WATCHDOG_ENABLED=false, since DB pool and engine
metrics won't be collected in that configuration.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* ci: retrigger CI checks

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: use labeled gauge for DB pool connection metrics

Replace 3 separate pool gauges (active, idle, total) with a single
`litellm_db_pool_connections` gauge using a `state` label. This is more
Prometheus-idiomatic and exposes all pg_stat_activity states (active,
idle, idle in transaction, etc.) without ambiguity about what "total"
includes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: address Greptile review — stale labels and fallback re-registration

- Zero out known pg_stat_activity states that are absent from the current
  query result, preventing stale gauge values from persisting.
- Simplify _get_or_create_gauge/counter by removing the fallback loop
  that could re-register an already-registered metric (ValueError).
- Add test for stale label clearing across collection cycles.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: include "unknown" in _PG_STATES for stale label clearing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: collect immediately on start and consolidate into single query

- Move sleep to end of loop so metrics appear on /metrics immediately
  after startup instead of after a 30s delay.
- Combine pool state and lock waiting queries into a single SQL query
  using conditional aggregation, halving per-cycle DB overhead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: prevent tight spin loop on collection error

Move asyncio.sleep outside the try/except so it always executes even
when _collect_engine_health() or _collect_pool_metrics() raises.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: add multiprocess_mode to _get_or_create_gauge initialization

- Include `multiprocess_mode` parameter to properly support multiprocessing in Gauge creation.
- Ensure consistent behavior for labeled and unlabeled Gauges.

* fix: handle invalid env var and document watchdog prerequisite

- Add try/except ValueError for PRISMA_METRICS_COLLECTION_INTERVAL_SECONDS
  to prevent proxy startup crash on non-numeric values (e.g. "30s")
- Document that DB metrics require both prometheus_system callback and
  PRISMA_HEALTH_WATCHDOG_ENABLED=true

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: use defensive null coalescing for query_raw row values

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* test: add invalid env var fallback test and fix mock signature

- Add test for non-numeric PRISMA_METRICS_COLLECTION_INTERVAL_SECONDS
- Add **kwargs to mock _patched_get_or_create_gauge for forward compat

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 08:49:46 -07:00
..
adding_provider feat(guardrails): team-based guardrail registration and approval workflow (#22459) 2026-03-02 22:06:49 -08:00
anthropic_unified docs(anthropic): add v1/messages → /responses parameter mapping reference 2026-03-05 15:51:19 +05:30
caching fix(ollama): thread api_base to get_model_info + graceful fallback (#21970) 2026-02-23 21:00:37 -08:00
completion fix: add prompt_cache_key and prompt_cache_retention support for OpenAI 2026-02-24 16:42:54 -08:00
contribute_integration docs(community.md): add new integration partner doc 2025-12-09 18:17:14 -08:00
contributing [Feat] Allow adding OpenAI compatible chat providers using .json + add public ai provider (#17448) 2025-12-04 17:59:25 -08:00
debugging
embedding docs: improve Getting Started page and SDK documentation structure (#17614) 2025-12-08 13:05:50 -08:00
extras fix: prompt registry 2026-02-18 00:34:54 +05:30
guides fix: prompt registry 2026-02-18 00:34:54 +05:30
integrations fix: prompt registry 2026-02-18 00:34:54 +05:30
langchain added tags to langchain 2025-09-10 00:32:26 -04:00
observability fix: req changes 2026-02-25 22:27:51 +05:30
pass_through Development environment setup (#22432) 2026-02-28 14:50:06 -08:00
projects fix: prompt registry 2026-02-18 00:34:54 +05:30
provider_registration docs openai 2025-12-04 18:32:23 -08:00
providers feat(vertex_ai): support explicit AWS credentials for WIF auth (#21472) 2026-03-06 09:27:20 -08:00
proxy feat(proxy): add Prisma DB pool and engine health metrics to Prometheus (#22655) 2026-03-09 08:49:46 -07:00
search feat(search): add Serper (serper.dev) as search provider (#23112) 2026-03-09 08:40:37 -07:00
secret_managers fix(ollama): thread api_base to get_model_info + graceful fallback (#21970) 2026-02-23 21:00:37 -08:00
troubleshoot feat: add in_flight_requests metric to /health/backlog + prometheus (#22319) 2026-02-27 18:00:50 -08:00
tutorials feat(proxy): client-side provider API key precedence for Anthropic /v1/messages 2026-03-06 18:20:46 +05:30
vector_stores Add vector store support for ragflow 2025-12-03 15:29:47 +05:30
a2a.md Agents - add max budget + tpm/rpm limiting per agent AND per agent session (#22849) 2026-03-07 19:12:42 -08:00
a2a_agent_headers.md docs(agents): add A2A agent authentication headers guide 2026-03-05 15:11:18 +05:30
a2a_agent_permissions.md [Docs] A2a - Permission management (#17515) 2025-12-04 17:29:47 -08:00
a2a_cost_tracking.md fix: prompt registry 2026-02-18 00:34:54 +05:30
a2a_invoking_agents.md fix: prompt registry 2026-02-18 00:34:54 +05:30
a2a_iteration_budgets.md Agents - add max budget + tpm/rpm limiting per agent AND per agent session (#22849) 2026-03-07 19:12:42 -08:00
aiohttp_benchmarks.md docs benchmarks 2025-05-24 17:43:38 -07:00
anthropic_count_tokens.md fix: prompt registry 2026-02-18 00:34:54 +05:30
apply_guardrail.md Implement Bedrock Guardrail apply_guardrail endpoint support (#15892) 2025-10-24 10:24:03 -07:00
assistants.md docs: improve Getting Started page and SDK documentation structure (#17614) 2025-12-08 13:05:50 -08:00
audio_transcription.md Add support of audio transcription for OVHcloud (#17305) 2025-12-01 18:26:39 -08:00
batches.md fix: prompt registry 2026-02-18 00:34:54 +05:30
bedrock_converse.md docs boto3 instructions 2025-10-16 16:34:56 -07:00
bedrock_invoke.md docs boto3 instructions 2025-10-16 16:34:56 -07:00
benchmarks.md fix(ollama): thread api_base to get_model_info + graceful fallback (#21970) 2026-02-23 21:00:37 -08:00
budget_manager.md
contact.md docs: update broken Slack invite links to support page (#16546) 2025-11-12 12:41:55 -08:00
container_files.md fix: prompt registry 2026-02-18 00:34:54 +05:30
containers.md [docs] add docs for containers files api + code interpreter on LiteLLM (#17749) 2025-12-09 18:11:28 -08:00
contributing.md fix(ollama): thread api_base to get_model_info + graceful fallback (#21970) 2026-02-23 21:00:37 -08:00
data_retention.md fix: prompt registry 2026-02-18 00:34:54 +05:30
data_security.md docs(data_security.md): data_security.md 2025-06-09 17:53:11 -07:00
default_code_snippet.md
enterprise.md fix(ollama): thread api_base to get_model_info + graceful fallback (#21970) 2026-02-23 21:00:37 -08:00
evals_api.md fix: prompt registry 2026-02-18 00:34:54 +05:30
exception_mapping.md Adds support for returning Azure Content Policy error information when exceptions from Azure OpenAI occur (#16231) 2025-11-08 16:04:36 -08:00
files_endpoints.md Add support for file content download for bedrock batches 2025-12-04 13:27:53 +05:30
fine_tuning.md fix(ollama): thread api_base to get_model_info + graceful fallback (#21970) 2026-02-23 21:00:37 -08:00
generateContent.md fix: Metadata / Trace ID Missing in S3 Streaming Callbacks 2026-02-25 14:16:42 +05:30
image_edits.md docs(openrouter): add image edit documentation 2026-03-03 14:50:41 -03:00
image_generation.md fix: prompt registry 2026-02-18 00:34:54 +05:30
image_variations.md
index.md fix: prompt registry 2026-02-18 00:34:54 +05:30
interactions.md fix(ollama): thread api_base to get_model_info + graceful fallback (#21970) 2026-02-23 21:00:37 -08:00
load_test.md fix: prompt registry 2026-02-18 00:34:54 +05:30
load_test_advanced.md fix: prompt registry 2026-02-18 00:34:54 +05:30
load_test_rpm.md docs: usaged-based routing perf warnings (#14080) 2025-08-29 17:31:12 -07:00
load_test_sdk.md
mcp.md Merge pull request #22750 from BerriAI/litellm_mcp_doc_update 2026-03-06 09:14:48 +05:30
mcp_control.md [Chore] update mcp documentation for header forwarding 2026-03-04 13:07:25 +05:30
mcp_cost.md [MCP Gateway] QA/Fixes - Ensure Team/Key level enforcement works for MCPs (#15305) 2025-10-07 17:34:48 -07:00
mcp_guardrail.md fix: prompt registry 2026-02-18 00:34:54 +05:30
mcp_oauth.md fix: prompt registry 2026-02-18 00:34:54 +05:30
mcp_openapi.md feat(mcp): allow admins to override tool name and description per MCP server (#22828) 2026-03-04 17:58:05 -08:00
mcp_public_internet.md fix: prompt registry 2026-02-18 00:34:54 +05:30
mcp_semantic_filter.md fix: prompt registry 2026-02-18 00:34:54 +05:30
mcp_troubleshoot.md fix: prompt registry 2026-02-18 00:34:54 +05:30
mcp_usage.md [MCP Gateway] QA/Fixes - Ensure Team/Key level enforcement works for MCPs (#15305) 2025-10-07 17:34:48 -07:00
migration.md
migration_policy.md
moderation.md docs(moderation.md): fix moderation quick start docs 2025-11-07 16:25:08 -08:00
ocr.md Enable local file support for OCR (#22133) 2026-02-27 10:50:02 -08:00
oidc.md fix: prompt registry 2026-02-18 00:34:54 +05:30
old_guardrails.md Use the -d flag in docs instead of -D (#12179) 2025-06-30 15:25:42 -07:00
projects.md
proxy_api.md Corrected docs updates sept 2025 (#14916) 2025-09-25 15:49:19 -07:00
proxy_auth.md fix: prompt registry 2026-02-18 00:34:54 +05:30
proxy_server.md
rag_ingest.md fix: prompt registry 2026-02-18 00:34:54 +05:30
rag_query.md fix: prompt registry 2026-02-18 00:34:54 +05:30
realtime.md feat(realtime): guardrails support for /v1/realtime WebSocket endpoint (#22152) 2026-02-25 21:34:22 -08:00
reasoning_content.md Add support for reasoning and tools viaconfig 2026-02-20 16:22:19 +05:30
rerank.md feat: Add IBM watsonx.ai rerank support (#21303) 2026-02-16 20:12:16 -08:00
response_api.md Add documentation related to responses websocket 2026-03-04 18:26:43 +05:30
response_api_compact.md fix: prompt registry 2026-02-18 00:34:54 +05:30
router_architecture.md
routing.md fix: prompt registry 2026-02-18 00:34:54 +05:30
rules.md
scheduler.md docs: usaged-based routing perf warnings (#14080) 2025-08-29 17:31:12 -07:00
sdk_custom_pricing.md
secret.md fix(ollama): thread api_base to get_model_info + graceful fallback (#21970) 2026-02-23 21:00:37 -08:00
set_keys.md
skills.md [Docs] Claude Skills API (#17052) 2025-11-24 15:32:03 -08:00
text_completion.md Guardrails - Responses API, Image Gen, Text completions, Audio transcriptions, Audio Speech, Rerank, Anthropic Messages API support via the unified apply_guardrails function (#15706) 2025-10-25 13:38:57 -07:00
text_to_speech.md fix: prompt registry 2026-02-18 00:34:54 +05:30
traffic_mirroring.md fix: prompt registry 2026-02-18 00:34:54 +05:30
troubleshoot.md fix: prompt registry 2026-02-18 00:34:54 +05:30
vector_store_files.md fix docs 2025-11-15 16:58:47 -08:00
vertex_batch_passthrough.md Litellm sameer oct staging (#15806) 2025-10-24 12:17:22 -07:00
videos.md [Feat] New Provider - Add RunwayML Provider for video generations (#16505) 2025-11-11 18:48:23 -08:00
wildcard_routing.md