mirror of
https://github.com/flibusta-apps/telegram_files_server.git
synced 2025-12-06 12:35:39 +01:00
Add metrics and healthcheck refactor
This commit is contained in:
@@ -67,9 +67,7 @@ async def delete_file(file_id: int):
|
|||||||
return uploaded_file
|
return uploaded_file
|
||||||
|
|
||||||
|
|
||||||
healthcheck_router = APIRouter(
|
healthcheck_router = APIRouter(tags=["healthcheck"])
|
||||||
prefix="/api/v1", dependencies=[Depends(check_token)], tags=["healthcheck"]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@healthcheck_router.get("/healthcheck")
|
@healthcheck_router.get("/healthcheck")
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
|
||||||
|
from prometheus_fastapi_instrumentator import Instrumentator
|
||||||
|
|
||||||
from app.on_start import on_start
|
from app.on_start import on_start
|
||||||
from app.views import router, healthcheck_router
|
from app.views import router, healthcheck_router
|
||||||
from core.db import database
|
from core.db import database
|
||||||
@@ -27,4 +29,6 @@ def start_app() -> FastAPI:
|
|||||||
if database_.is_connected:
|
if database_.is_connected:
|
||||||
await database_.disconnect()
|
await database_.disconnect()
|
||||||
|
|
||||||
|
Instrumentator().instrument(app).expose(app, include_in_schema=True)
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|||||||
33
poetry.lock
generated
33
poetry.lock
generated
@@ -349,6 +349,29 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
|
|||||||
[package.extras]
|
[package.extras]
|
||||||
dev = ["pre-commit", "tox"]
|
dev = ["pre-commit", "tox"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "prometheus-client"
|
||||||
|
version = "0.13.1"
|
||||||
|
description = "Python client for the Prometheus monitoring system."
|
||||||
|
category = "main"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.6"
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
twisted = ["twisted"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "prometheus-fastapi-instrumentator"
|
||||||
|
version = "5.7.1"
|
||||||
|
description = "Instrument your FastAPI with Prometheus metrics"
|
||||||
|
category = "main"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.6.0,<4.0.0"
|
||||||
|
|
||||||
|
[package.dependencies]
|
||||||
|
fastapi = ">=0.38.1,<1.0.0"
|
||||||
|
prometheus-client = ">=0.8.0,<1.0.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "psycopg2"
|
name = "psycopg2"
|
||||||
version = "2.9.2"
|
version = "2.9.2"
|
||||||
@@ -602,7 +625,7 @@ python-versions = "*"
|
|||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "1.1"
|
lock-version = "1.1"
|
||||||
python-versions = "^3.9"
|
python-versions = "^3.9"
|
||||||
content-hash = "afae087412314722a72e93d3e356d140950880627c81ddf22fe6cef54e7852ce"
|
content-hash = "aa58c9a30b09c09b109ae16173a2971c6afb85457d23ab7d2d38138d4cb74bf7"
|
||||||
|
|
||||||
[metadata.files]
|
[metadata.files]
|
||||||
aiosqlite = [
|
aiosqlite = [
|
||||||
@@ -949,6 +972,14 @@ pluggy = [
|
|||||||
{file = "pluggy-0.13.1-py2.py3-none-any.whl", hash = "sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d"},
|
{file = "pluggy-0.13.1-py2.py3-none-any.whl", hash = "sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d"},
|
||||||
{file = "pluggy-0.13.1.tar.gz", hash = "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0"},
|
{file = "pluggy-0.13.1.tar.gz", hash = "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0"},
|
||||||
]
|
]
|
||||||
|
prometheus-client = [
|
||||||
|
{file = "prometheus_client-0.13.1-py3-none-any.whl", hash = "sha256:357a447fd2359b0a1d2e9b311a0c5778c330cfbe186d880ad5a6b39884652316"},
|
||||||
|
{file = "prometheus_client-0.13.1.tar.gz", hash = "sha256:ada41b891b79fca5638bd5cfe149efa86512eaa55987893becd2c6d8d0a5dfc5"},
|
||||||
|
]
|
||||||
|
prometheus-fastapi-instrumentator = [
|
||||||
|
{file = "prometheus-fastapi-instrumentator-5.7.1.tar.gz", hash = "sha256:5371f1b494e2b00017a02898d854119b4929025d1a203670b07b3f42dd0b5526"},
|
||||||
|
{file = "prometheus_fastapi_instrumentator-5.7.1-py3-none-any.whl", hash = "sha256:da40ea0df14b0e95d584769747fba777522a8df6a8c47cec2edf798f1fff49b5"},
|
||||||
|
]
|
||||||
psycopg2 = [
|
psycopg2 = [
|
||||||
{file = "psycopg2-2.9.2-cp310-cp310-win32.whl", hash = "sha256:6796ac614412ce374587147150e56d03b7845c9e031b88aacdcadc880e81bb38"},
|
{file = "psycopg2-2.9.2-cp310-cp310-win32.whl", hash = "sha256:6796ac614412ce374587147150e56d03b7845c9e031b88aacdcadc880e81bb38"},
|
||||||
{file = "psycopg2-2.9.2-cp310-cp310-win_amd64.whl", hash = "sha256:dfc32db6ce9ecc35a131320888b547199f79822b028934bb5b332f4169393e15"},
|
{file = "psycopg2-2.9.2-cp310-cp310-win_amd64.whl", hash = "sha256:dfc32db6ce9ecc35a131320888b547199f79822b028934bb5b332f4169393e15"},
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ python-multipart = "^0.0.5"
|
|||||||
httpx = "^0.22.0"
|
httpx = "^0.22.0"
|
||||||
Telethon = "^1.24.0"
|
Telethon = "^1.24.0"
|
||||||
cryptg = "^0.2.post4"
|
cryptg = "^0.2.post4"
|
||||||
|
prometheus-fastapi-instrumentator = "^5.7.1"
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
pytest = "^5.2"
|
pytest = "^5.2"
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
|
|
||||||
response = httpx.get(
|
response = httpx.get("http://localhost:8080/healthcheck")
|
||||||
"http://localhost:8080/api/v1/healthcheck",
|
|
||||||
headers={"Authorization": os.environ["API_KEY"]},
|
|
||||||
)
|
|
||||||
print(f"HEALTHCHECK STATUS: {response.status_code}")
|
print(f"HEALTHCHECK STATUS: {response.status_code}")
|
||||||
exit(0 if response.status_code == 200 else 1)
|
exit(0 if response.status_code == 200 else 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user