Production-ready actuator endpoints for FastAPI (health, metrics, info)
Project description
Fastuator
Production-ready monitoring toolkit for FastAPI applications.
Kubernetes probes, Prometheus metrics, and health checks in one line.
✨ Features
- 🏥 Health Checks: Aggregated health status with customizable checks
- 🔍 K8s Probes: Built-in liveness and readiness endpoints
- 📊 Prometheus Metrics: Auto-instrumented HTTP metrics
- ℹ️ System Info: Build version and platform details
- 🎯 Zero Config: Works out of the box with sensible defaults
- ⚡ 100% Test Coverage: Battle-tested and production-ready
📦 Installation
pip install fastuator
🚀 Quick Start
from fastapi import FastAPI
from fastuator import Fastuator
app = FastAPI()
Fastuator(app) # That's it!
Available Endpoints:
| Endpoint | Description |
|---|---|
GET /fastuator/health |
Aggregated health status with optional details |
GET /fastuator/liveness |
Kubernetes liveness probe (critical checks only) |
GET /fastuator/readiness |
Kubernetes readiness probe (all dependencies) |
GET /fastuator/metrics |
Prometheus-compatible metrics |
GET /fastuator/info |
Application and system information |
📖 Usage
Basic Setup
from fastapi import FastAPI
from fastuator import Fastuator
app = FastAPI()
# Use default configuration
Fastuator(app)
# Custom prefix
Fastuator(app, prefix="/monitoring")
Custom Health Checks
from fastuator import Fastuator
app = FastAPI()
# Define custom health checks
async def database_health():
try:
# Check database connection
await db.execute("SELECT 1")
return {"status": "UP", "database": "connected"}
except Exception as e:
return {"status": "DOWN", "database": str(e)}
async def redis_health():
try:
await redis.ping()
return {"status": "UP", "redis": "connected"}
except Exception:
return {"status": "DOWN", "redis": "unreachable"}
# Register custom checks
Fastuator(
app,
health_checks=[database_health, redis_health],
readiness_checks=[database_health, redis_health],
liveness_checks=[], # No external dependencies for liveness
)
Health Check Response
Without details:
curl http://localhost:8000/fastuator/health
{"status": "UP"}
With details:
curl http://localhost:8000/fastuator/health?show_details=true
{
"status": "UP",
"components": {
"check_0": {
"status": "UP",
"cpu_percent": 45.2
},
"check_1": {
"status": "UP",
"memory_percent": 62.1,
"memory_available_mb": 4096
}
}
}
☸️ Kubernetes Integration
Deployment Example
apiVersion: apps/v1
kind: Deployment
metadata:
name: fastapi-app
spec:
template:
spec:
containers:
- name: app
image: myapp:latest
ports:
- containerPort: 8000
livenessProbe:
httpGet:
path: /fastuator/liveness
port: 8000
initialDelaySeconds: 10
periodSeconds: 10
readinessProbe:
httpGet:
path: /fastuator/readiness
port: 8000
initialDelaySeconds: 5
periodSeconds: 5
📊 Prometheus Metrics
Fastuator automatically collects the following metrics:
http_requests_total: Total HTTP requests (counter)http_request_duration_seconds: Request duration histogramapp_health_status: Health status gauge (1=UP, 0=DOWN)
Scrape configuration:
scrape_configs:
- job_name: 'fastapi'
static_configs:
- targets: ['localhost:8000']
metrics_path: '/fastuator/metrics'
⚙️ Configuration
Fastuator(
app,
prefix="/fastuator", # URL prefix for all endpoints
health_checks=[...], # List of health check functions
liveness_checks=[...], # Checks for liveness probe
readiness_checks=[...], # Checks for readiness probe
enable_metrics=True, # Enable Prometheus metrics
)
🧪 Built-in Health Checks
Fastuator includes these health checks by default:
- CPU Usage: Reports DOWN if CPU > 90%
- Memory Usage: Reports DOWN if memory > 90%
- Disk Usage: Reports DOWN if disk > 90%
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Run tests (
pytest --cov=fastuator) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
Inspired by Spring Boot Actuator.
📚 Related Projects
- FastAPI - Modern web framework for Python
- Prometheus - Monitoring and alerting toolkit
- Kubernetes - Container orchestration platform
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastuator-0.0.1.tar.gz.
File metadata
- Download URL: fastuator-0.0.1.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
303187dc2635fe6752880b8464f9f43020da2aa8654d554773c7262a59a10772
|
|
| MD5 |
4f516167af365d634bed0584a4bb998c
|
|
| BLAKE2b-256 |
22c0cc7921faca4fe9e674fc2773cb27b0de2d11e5c9931ba234493a2931882b
|
File details
Details for the file fastuator-0.0.1-py3-none-any.whl.
File metadata
- Download URL: fastuator-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbd5f82663a9e59d023e81445515e65f96100f313c385940377b696b11f89c73
|
|
| MD5 |
0298829977cfd5e9915dc995caf33068
|
|
| BLAKE2b-256 |
eefe811d99cb39d67732650e59ad2d80a22664a08181f707986d285b5d44d7cf
|