import { NextResponse } from "next/server"; export const dynamic = "force-dynamic"; export const runtime = "nodejs"; /** * GET /api/metrics * * Proxies llama.cpp's /metrics (Prometheus) endpoint. The dashboard container * is on the same Docker network as llama, so http://llama:8080/metrics works. * * Returns plain text (Prometheus exposition format). */ export async function GET() { try { const res = await fetch("http://llama:8080/metrics", { cache: "no-store", signal: AbortSignal.timeout(5000), }); if (!res.ok) { return NextResponse.json( { ok: false, error: `llama returned ${res.status}`, raw: await res.text().catch(() => ""), }, { status: res.status } ); } const text = await res.text(); // Return as plain text — the frontend can render it as
return new Response(text, {
headers: { "Content-Type": "text/plain; version=0.0.4; charset=utf-8" },
});
} catch (err) {
return NextResponse.json(
{
ok: false,
error: (err as Error).message,
hint: "llama container must be running and started with --metrics flag",
},
{ status: 503 }
);
}
}