/
Mihaham
/
Table-Time
Обзор
Документация
Войти
/
Mihaham
/
Table-Time
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
services/api/app/modules/admin/prometheus_proxy.py
32 строки
1 KB
MihahamYT
feat: dedicated web panels for all 46 games
14 июн 2026, 21:36
14 июн 2026, 21:36
4e11c3f
Код
Авторство
О чём код?
import httpx from app.config import get_settings from app.observability.metrics import is_allowed_promql class PrometheusProxy: def __init__(self) -> None: self.settings = get_settings() async def query_range(self, query: str, start: float, end: float, step: int = 60) -> dict: if not is_allowed_promql(query): return {"status": "error", "error": "Query not allowed"} url = f"{self.settings.prometheus_url.rstrip('/')}/api/v1/query_range" params = {"query": query, "start": start, "end": end, "step": step} try: async with httpx.AsyncClient(timeout=10.0) as client: response = await client.get(url, params=params) response.raise_for_status() return response.json() except Exception as exc: return {"status": "error", "error": str(exc)} async def ping(self) -> bool: url = f"{self.settings.prometheus_url.rstrip('/')}/-/ready" try: async with httpx.AsyncClient(timeout=3.0) as client: response = await client.get(url) return response.status_code == 200 except Exception: return False