Spaces:
Sleeping
Sleeping
| from fastapi import APIRouter | |
| from src.api.monitoring.metrics import ( | |
| get_monitoring_summary, | |
| get_recent_requests, | |
| get_endpoint_usage, | |
| get_latency_by_endpoint, | |
| get_inference_step_metrics, | |
| get_recent_errors, | |
| get_top_recommended_crops, | |
| get_requests_over_time, | |
| ) | |
| from src.api.monitoring.drift import ( | |
| get_input_drift_summary, | |
| get_numeric_psi, | |
| get_distribution_comparison, | |
| ) | |
| router = APIRouter( | |
| prefix="/monitoring", | |
| tags=["Monitoring"], | |
| ) | |
| def monitoring_summary(): | |
| return get_monitoring_summary() | |
| def monitoring_recent_requests( | |
| limit: int = 20, | |
| endpoint: str = "all", | |
| time_window: str = "all", | |
| ): | |
| return { | |
| "requests": get_recent_requests( | |
| limit=limit, | |
| endpoint=endpoint, | |
| time_window=time_window, | |
| ) | |
| } | |
| def monitoring_endpoint_usage( | |
| endpoint: str = "all", | |
| time_window: str = "all", | |
| ): | |
| return { | |
| "endpoint_usage": get_endpoint_usage( | |
| endpoint=endpoint, | |
| time_window=time_window, | |
| ) | |
| } | |
| def monitoring_latency_by_endpoint( | |
| endpoint: str = "all", | |
| time_window: str = "all", | |
| ): | |
| return { | |
| "latency_by_endpoint": get_latency_by_endpoint( | |
| endpoint=endpoint, | |
| time_window=time_window, | |
| ) | |
| } | |
| def monitoring_inference_steps(): | |
| return { | |
| "inference_steps": get_inference_step_metrics() | |
| } | |
| def monitoring_errors( | |
| limit: int = 20, | |
| endpoint: str = "all", | |
| time_window: str = "all", | |
| ): | |
| return { | |
| "errors": get_recent_errors( | |
| limit=limit, | |
| endpoint=endpoint, | |
| time_window=time_window, | |
| ) | |
| } | |
| def monitoring_top_recommended_crops( | |
| limit: int = 10, | |
| ): | |
| return { | |
| "top_recommended_crops": get_top_recommended_crops( | |
| limit=limit | |
| ) | |
| } | |
| def monitoring_requests_over_time( | |
| endpoint: str = "all", | |
| time_window: str = "all", | |
| ): | |
| return { | |
| "requests_over_time": get_requests_over_time( | |
| endpoint=endpoint, | |
| time_window=time_window, | |
| ) | |
| } | |
| def monitoring_input_drift(): | |
| return { | |
| "input_drift": get_input_drift_summary() | |
| } | |
| def monitoring_psi(): | |
| return { | |
| "psi": get_numeric_psi() | |
| } | |
| def monitoring_distribution_comparison( | |
| feature: str, | |
| ): | |
| return get_distribution_comparison(feature) |