File size: 935 Bytes
a17a837
 
6e9d8ea
a17a837
 
 
 
 
 
 
 
6e9d8ea
 
a17a837
6e9d8ea
a17a837
6e9d8ea
 
a17a837
 
6e9d8ea
 
 
 
 
 
a17a837
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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