Files
snake-python/server/blueprints/metrics.py
T

26 lines
750 B
Python

from quart import Blueprint, jsonify, request
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_runtime.game_last_seen_unix,
server.game_runtime.game_move_counts,
)
if 'prometheus' in (request.headers.get('User-Agent') or '').lower():
return (
server.metrics_collector.build_prometheus_metrics(snapshot),
200,
{'Content-Type': 'text/plain; version=0.0.4; charset=utf-8'},
)
return jsonify(snapshot)
return blueprint