31 lines
890 B
Python
31 lines
890 B
Python
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_runtime.game_last_seen_unix,
|
|
server.game_runtime.game_move_counts,
|
|
)
|
|
return jsonify(snapshot)
|
|
|
|
@blueprint.get('/metrics/prometheus')
|
|
async def metrics_prometheus():
|
|
snapshot = await server.metrics_collector.build_snapshot(
|
|
server.game_runtime.game_last_seen_unix,
|
|
server.game_runtime.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
|