change metrics endpoint to return json by default and when the useragent contains prometheus to return the output as prometheus string format
Build and Push Docker Container / build-and-push (push) Successful in 4m53s
Build and Push Docker Container / build-and-push (push) Successful in 4m53s
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
from quart_common.web.decorators import restrict_ip_addresses, require_user_agent
|
||||
|
||||
from quart import Blueprint, jsonify
|
||||
from quart import Blueprint, jsonify, request
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -10,26 +8,18 @@ def create_metrics_blueprint(server:'Server') -> Blueprint:
|
||||
blueprint = Blueprint('metrics', __name__)
|
||||
|
||||
@blueprint.get('/metrics')
|
||||
@restrict_ip_addresses(allow=['127.0.0.1', '192.168.200.0/24'], abort_code=404)
|
||||
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)
|
||||
|
||||
@blueprint.get('/metrics/prometheus')
|
||||
@restrict_ip_addresses(allow=['127.0.0.1', '192.168.188.0/24', '192.168.200.0/24'], abort_code=404)
|
||||
@require_user_agent("prometheus", abort_code=404)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user