fix
This commit is contained in:
24
app/utils/monitoring.py
Normal file
24
app/utils/monitoring.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
import datetime
|
||||
import requests
|
||||
|
||||
|
||||
class Monitroing:
|
||||
def __init__(self):
|
||||
self.executor = ThreadPoolExecutor(max_workers=1)
|
||||
|
||||
def send_metric(self, start: datetime.datetime, end: datetime.datetime, endpoint: str, status_code: int, method: str):
|
||||
def send():
|
||||
requests.post(f'http://monitoring:1237/api/v1/metrics/endpoint', json={
|
||||
'timestamp': start.strftime("%Y-%m-%dT%H:%M:%S") + "Z",
|
||||
'service': 'configurator',
|
||||
'endpoint': endpoint,
|
||||
'status_code': status_code,
|
||||
'response_time': (end - start).microseconds // 1000,
|
||||
'method': method,
|
||||
})
|
||||
|
||||
self.executor.submit(send)
|
||||
|
||||
|
||||
monitoring = Monitroing()
|
||||
Reference in New Issue
Block a user