Spaces:
Runtime error
Runtime error
Download monitoring.py from vriddhisaini/multi-agent-verifier: direct link, hf CLI and curl.
- Browser
- Download file 935 Bytes
-
https://huggingface.co/spaces/vriddhisaini/multi-agent-verifier/resolve/main/monitoring.py
- Command line
-
hf download hf://spaces/vriddhisaini/multi-agent-verifier/monitoring.py
-
curl -L -o monitoring.py https://huggingface.co/spaces/vriddhisaini/multi-agent-verifier/resolve/main/monitoring.py
935 Bytes
| import logging | |
| import time | |
| from prometheus_client import Counter, Histogram, start_http_server | |
| # Only use console logging (no file handler) | |
| logging.basicConfig( | |
| level=logging.INFO, | |
| format='%(asctime)s - %(levelname)s - %(message)s', | |
| handlers=[logging.StreamHandler()] # removed FileHandler | |
| ) | |
| REQUEST_COUNT = Counter('gradio_requests_total', 'Total requests') | |
| REQUEST_DURATION = Histogram('gradio_request_duration_seconds', 'Latency') | |
| start_http_server(8000) | |
| def monitor_request(func): | |
| def wrapper(*args, **kwargs): | |
| start = time.time() | |
| REQUEST_COUNT.inc() | |
| try: | |
| result = func(*args, **kwargs) | |
| REQUEST_DURATION.observe(time.time() - start) | |
| logging.info(f"{func.__name__} took {time.time()-start:.2f}s") | |
| return result | |
| except Exception as e: | |
| logging.error(f"Error in {func.__name__}: {e}") | |
| raise | |
| return wrapper |