26 lines
844 B
Python
26 lines
844 B
Python
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,
|
|
'environment': 'production',
|
|
})
|
|
|
|
self.executor.submit(send)
|
|
|
|
|
|
monitoring = Monitroing()
|