mirror of
https://github.com/System-End/nephthys.git
synced 2026-04-19 18:35:14 +00:00
Add a Prometheus metrics endpoint (#84)
* Add a Prometheus metrics endpoint * Add starlette_exporter metrics * Add Prisma metrics to `/metrics`
This commit is contained in:
parent
1a3818e413
commit
b54694e62d
3 changed files with 524 additions and 465 deletions
|
|
@ -1,9 +1,13 @@
|
|||
from prometheus_client import CONTENT_TYPE_LATEST
|
||||
from prometheus_client import generate_latest
|
||||
from slack_bolt.adapter.starlette.async_handler import AsyncSlackRequestHandler
|
||||
from starlette.applications import Starlette
|
||||
from starlette.requests import Request
|
||||
from starlette.responses import JSONResponse
|
||||
from starlette.responses import RedirectResponse
|
||||
from starlette.responses import Response
|
||||
from starlette.routing import Route
|
||||
from starlette_exporter import PrometheusMiddleware
|
||||
|
||||
from nephthys.__main__ import main
|
||||
from nephthys.api.stats import stats
|
||||
|
|
@ -36,6 +40,14 @@ async def health(req: Request):
|
|||
)
|
||||
|
||||
|
||||
async def metrics(req: Request):
|
||||
"""Prometheus metrics endpoint"""
|
||||
main_metrics: bytes = generate_latest()
|
||||
prisma_metrics = await env.db.get_metrics(format="prometheus")
|
||||
all_metrics = main_metrics + prisma_metrics.encode("utf-8")
|
||||
return Response(all_metrics, media_type=CONTENT_TYPE_LATEST)
|
||||
|
||||
|
||||
async def root(req: Request):
|
||||
return RedirectResponse(url="https://github.com/hackclub/nephthys")
|
||||
|
||||
|
|
@ -48,6 +60,25 @@ app = Starlette(
|
|||
Route(path="/api/stats", endpoint=stats, methods=["GET"]),
|
||||
Route(path="/api/user", endpoint=user_stats, methods=["GET"]),
|
||||
Route(path="/health", endpoint=health, methods=["GET"]),
|
||||
Route(path="/metrics", endpoint=metrics, methods=["GET"]),
|
||||
],
|
||||
lifespan=main,
|
||||
)
|
||||
|
||||
app.add_middleware(
|
||||
PrometheusMiddleware,
|
||||
app_name="nephthys",
|
||||
buckets=[
|
||||
0.001,
|
||||
0.01,
|
||||
0.025,
|
||||
0.05,
|
||||
0.1,
|
||||
0.25,
|
||||
0.5,
|
||||
0.75,
|
||||
1.0,
|
||||
1.5,
|
||||
2.5,
|
||||
],
|
||||
)
|
||||
|
|
|
|||
|
|
@ -11,11 +11,13 @@ dependencies = [
|
|||
"matplotlib>=3.10.3",
|
||||
"numpy>=2.3.1",
|
||||
"prisma>=0.15.0",
|
||||
"prometheus-client>=0.23.1",
|
||||
"pydantic>=2.11.5",
|
||||
"python-dotenv>=1.1.0",
|
||||
"pytz>=2025.2",
|
||||
"slack-bolt>=1.23.0",
|
||||
"starlette>=0.46.1",
|
||||
"starlette-exporter>=0.23.0",
|
||||
"thefuzz>=0.22.1",
|
||||
"uvicorn>=0.34.0",
|
||||
"uvloop>=0.21.0",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue