Compare commits
No commits in common. "aa309890cd5a284c831f53c55d1eec321531eb9e" and "73569e08396a6ef3bc207571791cb55015409947" have entirely different histories.
aa309890cd
...
73569e0839
@ -6,7 +6,6 @@ services:
|
|||||||
image: mathwave/sprint-repo:configurator
|
image: mathwave/sprint-repo:configurator
|
||||||
networks:
|
networks:
|
||||||
- configurator-development
|
- configurator-development
|
||||||
- monitoring
|
|
||||||
environment:
|
environment:
|
||||||
MONGO_HOST: "mongo.develop.sprinthub.ru"
|
MONGO_HOST: "mongo.develop.sprinthub.ru"
|
||||||
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
|
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
|
||||||
@ -21,5 +20,3 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
configurator-development:
|
configurator-development:
|
||||||
external: true
|
external: true
|
||||||
monitoring:
|
|
||||||
external: true
|
|
||||||
|
@ -6,7 +6,6 @@ services:
|
|||||||
image: mathwave/sprint-repo:configurator
|
image: mathwave/sprint-repo:configurator
|
||||||
networks:
|
networks:
|
||||||
- configurator
|
- configurator
|
||||||
- monitoring
|
|
||||||
environment:
|
environment:
|
||||||
MONGO_HOST: "mongo.sprinthub.ru"
|
MONGO_HOST: "mongo.sprinthub.ru"
|
||||||
MONGO_PASSWORD: $MONGO_PASSWORD_PROD
|
MONGO_PASSWORD: $MONGO_PASSWORD_PROD
|
||||||
@ -21,5 +20,3 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
configurator:
|
configurator:
|
||||||
external: true
|
external: true
|
||||||
monitoring:
|
|
||||||
external: true
|
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
import datetime
|
|
||||||
import zoneinfo
|
|
||||||
from fastapi import Request, Response
|
|
||||||
from starlette.middleware.base import BaseHTTPMiddleware
|
|
||||||
|
|
||||||
from app.utils.monitoring import monitoring
|
|
||||||
|
|
||||||
class MetricsMiddleware(BaseHTTPMiddleware):
|
|
||||||
async def dispatch(self, request: Request, call_next):
|
|
||||||
start = datetime.datetime.now(zoneinfo.ZoneInfo("Europe/Moscow"))
|
|
||||||
response: Response = await call_next(request)
|
|
||||||
end = datetime.datetime.now(zoneinfo.ZoneInfo("Europe/Moscow"))
|
|
||||||
monitoring.send_metric(start, end, request.url.path, response.status_code, request.method)
|
|
||||||
return response
|
|
@ -1,24 +0,0 @@
|
|||||||
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()
|
|
Loading…
Reference in New Issue
Block a user