move route code out of server into own blueprints and cleanup the codebase
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
from quart import Blueprint, jsonify
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from server.Server import Server
|
||||
|
||||
def create_metrics_blueprint(server:"Server") -> Blueprint:
|
||||
blueprint = Blueprint("metrics", __name__)
|
||||
|
||||
@blueprint.get("/metrics")
|
||||
async def metrics():
|
||||
snapshot = await server.metrics_collector.build_snapshot(
|
||||
server.game_last_seen_unix,
|
||||
server.game_move_counts,
|
||||
)
|
||||
return jsonify(snapshot)
|
||||
|
||||
@blueprint.get("/metrics/prometheus")
|
||||
async def metrics_prometheus():
|
||||
snapshot = await server.metrics_collector.build_snapshot(
|
||||
server.game_last_seen_unix,
|
||||
server.game_move_counts,
|
||||
)
|
||||
return (
|
||||
server.metrics_collector.build_prometheus_metrics(snapshot),
|
||||
200,
|
||||
{"Content-Type": "text/plain; version=0.0.4; charset=utf-8"},
|
||||
)
|
||||
|
||||
return blueprint
|
||||
Reference in New Issue
Block a user