prometheus-fastapi-metrics
CommunityAdd production-safe Prometheus metrics to FastAPI.
Software Engineering#fastapi#observability#grafana#prometheus#metrics instrumentation#histogram buckets#label cardinality
Authorsaintgo7
Version1.0.0
Installs0
System Documentation
What problem does it solve?
This Skill prevents blind monitoring and guesswork by showing how to add Prometheus custom metrics to a FastAPI service in a way that stays production-safe, especially around label cardinality and observability readiness.
Core Features & Use Cases
- Production-ready /metrics endpoint: Exposes Prometheus scrape data via
prometheus_client.generate_latest()for FastAPI. - 3-location metric recording: Implements a clear pattern for placing metrics in middleware (request lifecycle), routes (domain/model/token metrics), and services (quota/rejection outcomes).
- Cardinality safety rules: Provides concrete guardrails to avoid Prometheus time-series explosions (path whitelisting, known enums for model/reason, grouping status codes, and banning high-cardinality identifiers).
- Histogram bucket guidance: Recommends latency bucket selection aligned with expected SLO ranges (e.g., LLM gateway latencies in ms).
- Grafana dashboard starter: Supplies a template dashboard driven by the metric schema for fast visualization and alert panel setup.
Quick Start
Use the skill to instrument your FastAPI app by following the provided 3-location pattern and applying the cardinality rules so you can immediately start scraping and building Grafana panels from the exported metrics.
Dependency Matrix
Required Modules
None requiredComponents
templates
💻 Claude Code Installation
Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.
Please help me install this Skill: Name: prometheus-fastapi-metrics Download link: https://github.com/saintgo7/claude-skills/archive/main.zip#prometheus-fastapi-metrics Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
Agent Skills Search Helper
Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.