43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
import httpx
|
|
from fastapi import APIRouter
|
|
|
|
from app.config import get_settings
|
|
from app.homelab.comfyui import _use_anima
|
|
|
|
router = APIRouter(prefix="/homelab", tags=["homelab"])
|
|
|
|
|
|
def _probe(url: str, *, timeout: float = 10.0) -> dict:
|
|
try:
|
|
with httpx.Client(timeout=timeout) as client:
|
|
response = client.get(url)
|
|
body = response.text[:500]
|
|
return {
|
|
"ok": response.status_code < 400,
|
|
"status_code": response.status_code,
|
|
"preview": body,
|
|
}
|
|
except Exception as exc:
|
|
return {"ok": False, "error": str(exc)}
|
|
|
|
|
|
@router.get("/status")
|
|
def homelab_status() -> dict:
|
|
settings = get_settings()
|
|
comfy_backend = "anima" if _use_anima(settings) else "checkpoint"
|
|
return {
|
|
"openmeteo": _probe(f"{settings.openmeteo_base_url.rstrip('/')}/v1/forecast?latitude=0&longitude=0¤t=temperature_2m"),
|
|
"comfyui": _probe(f"{settings.comfyui_base_url.rstrip('/')}/system_stats"),
|
|
"netdata": _probe(f"{settings.netdata_base_url.rstrip('/')}/api/v1/info"),
|
|
"rp_chat": _probe(f"{settings.rp_chat_base_url.rstrip('/')}/health"),
|
|
"config": {
|
|
"openmeteo_base_url": settings.openmeteo_base_url,
|
|
"comfyui_base_url": settings.comfyui_base_url,
|
|
"comfyui_backend": comfy_backend,
|
|
"comfyui_unet": settings.comfyui_unet,
|
|
"netdata_base_url": settings.netdata_base_url,
|
|
"rp_chat_base_url": settings.rp_chat_base_url,
|
|
"rp_chat_enabled": settings.rp_chat_enabled,
|
|
},
|
|
}
|