Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
add a prometheus metrics endpoint
zeevo95452866b22d
diff --git a/docs/DETAILS.md b/docs/DETAILS.mdindex b93cf3925..cc2d8c95e 100644--- a/docs/DETAILS.md+++ b/docs/DETAILS.md@@ -651,6 +651,7 @@ The server listens on `http://127.0.0.1:8080` (change with `--port` in setup, or| Save / restore the conversation to a file (session files, below) | `POST /slots/0?action=save\|restore` || Everything the Monitor tab shows (engine, live state, last requests, hardware) | `GET /metrics` || The same for Prometheus, with vLLM's metric names (asked with `Accept: text/plain` or `?format=prometheus`) | `GET /metrics` |+| Request totals and what is running in Prometheus' text format, under llama-server's metric names | `GET /metrics/prometheus` || The MCP servers, their state and tools ([below](#tools-from-mcp-servers)) | `GET /mcp` |`GET /metrics` answers a Prometheus scrape (`Accept: text/plain` or `application/openmetrics-text`) in the textdiff --git a/serve/server.py b/serve/server.pyindex b6e926fa2..d3b27d477 100644--- a/serve/server.py+++ b/serve/server.py@@ -3229,6 +3229,35 @@ class Service:"hardware_static":tel["static"], "history": tel["history"], "time": now}+ def prometheus(self) -> str:+ """GET /metrics/prometheus: the totals and what is running in Prometheus' text format, under llama-server's+ metric names (llamacpp:*) so its dashboards work unchanged; the drafts and requests as strata:*."""+ with self.status_lock:+ s, t = dict(self.status), dict(self.totals)+ running = len(self.live_reqs) or int(bool(s.get("busy")))+ prompt_n = t["prompt_tokens"] - t["reused"] # what was read, as llama.cpp counts it+ prompt_s, decode_s = t["prompt_ms"] / 1000, t["decode_ms"] / 1000+ rows = [+ ("llamacpp:prompt_tokens_total", "counter", "Prompt tokens read", prompt_n),+ ("llamacpp:prompt_tokens_cached_total", "counter", "Prompt tokens the conversation cache already held",+ t["reused"]),+ ("llamacpp:prompt_seconds_total", "counter", "Prompt read time", prompt_s),+ ("llamacpp:tokens_predicted_total", "counter", "Tokens generated", t["output_tokens"]),+ ("llamacpp:tokens_predicted_seconds_total", "counter", "Generation time", decode_s),+ ("llamacpp:prompt_tokens_seconds", "gauge", "Average prompt read throughput in tokens/s",+ prompt_n / prompt_s if prompt_s else 0),+ ("llamacpp:predicted_tokens_seconds", "gauge", "Average generation throughput in tokens/s",+ t["output_tokens"] / decode_s if decode_s else 0),+ ("llamacpp:requests_processing", "gauge", "Requests running", running),+ ("llamacpp:requests_deferred", "gauge", "Requests waiting their turn", s.get("queued") or 0),+ ("strata:requests_total", "counter", "Requests finished", t["requests"]),+ ("strata:drafts_offered_total", "counter", "Speculative draft tokens offered", t["drafts_offered"]),+ ("strata:drafts_accepted_total", "counter", "Speculative draft tokens accepted", t["drafts_accepted"]),+ ("strata:model_loaded", "gauge", "1 while the model is loaded", int(self.loaded())),+ ]+ return "".join(f"# HELP {name} {help_}\n# TYPE {name} {kind}\n{name} {value}\n"+ for name, kind, help_, value in rows)+def v1_status(self) -> dict:"""GET /v1/status: what this server is and does, for a client that would rather ask than guess (a front-endthat polls its OpenAI-compatible server's status, collabosm's for one): the model and its window, images,@@ -4679,6 +4708,15 @@ def make_handler(svc: Service):self.end_headers()self.wfile.write(body)return+ if path == "/metrics/prometheus":+ if self._authorized():+ body = svc.prometheus().encode()+ self.send_response(200)+ self.send_header("Content-Type", "text/plain; version=0.0.4; charset=utf-8")+ self.send_header("Content-Length", str(len(body)))+ self.end_headers()+ self.wfile.write(body)+ returnif path == "/metrics":from serve import prometheusif prometheus.wants_prometheus(self.headers.get("Accept", ""), urlsplit(self.path).query):diff --git a/serve/test_server.py b/serve/test_server.pyindex c35998736..f8a1f58fb 100644--- a/serve/test_server.py+++ b/serve/test_server.py@@ -1926,6 +1926,42 @@ class DraftCounts(unittest.TestCase):self.assertEqual((m["totals"]["drafts_offered"], m["totals"]["drafts_accepted"]), (17, 10))+class PrometheusMetrics(unittest.TestCase):+ """GET /metrics/prometheus: the totals in Prometheus' text format, under llama-server's names."""++ def test_totals(self):+ tok = ByteTokenizer()+ engine = DoneLineEngine(tok, "</think>\n\nok", max_context=CTX, done_lines=[+ "DONE 4 20 400.0 200.0 stop 7 12 5", # 5 of the prompt's tokens reused+ "DONE 4 20 400.0 200.0 stop 3 5 0"])+ svc = Service(engine, tok, ChatTemplate(ROOT / "serve/chat_template.jinja"))+ httpd = serve(svc, port=0)+ base = f"http://127.0.0.1:{httpd.server_address[1]}"+ try:+ for _ in range(2):+ body = json.dumps({"model": "m", "max_tokens": 10, "messages": [{"role": "user", "content": "hi"}]})+ with urllib.request.urlopen(urllib.request.Request(base + "/v1/chat/completions", data=body.encode(),+ headers={"Content-Type": "application/json"}),+ timeout=30) as r:+ self.assertEqual(r.status, 200)+ with urllib.request.urlopen(base + "/metrics/prometheus", timeout=10) as r:+ self.assertTrue(r.headers["Content-Type"].startswith("text/plain"))+ text = r.read().decode()+ finally:+ httpd.shutdown()+ httpd.server_close()+ m = {line.split()[0]: float(line.split()[1]) for line in text.splitlines() if not line.startswith("#")}+ t = svc.totals+ self.assertEqual(m["llamacpp:prompt_tokens_total"], t["prompt_tokens"] - 5)+ self.assertEqual(m["llamacpp:prompt_tokens_cached_total"], 5)+ self.assertEqual(m["llamacpp:prompt_seconds_total"], 0.8)+ self.assertEqual(m["llamacpp:tokens_predicted_total"], t["output_tokens"])+ self.assertEqual(m["llamacpp:tokens_predicted_seconds_total"], 0.4)+ self.assertEqual((m["llamacpp:requests_processing"], m["llamacpp:requests_deferred"]), (0, 0))+ self.assertEqual((m["strata:requests_total"], m["strata:drafts_offered_total"],+ m["strata:drafts_accepted_total"]), (2, 17, 10))++class PcieShare(unittest.TestCase):"""#588: the hit rate stays the VRAM share of the lookups; the routed experts the GPU read over PCIe (the DONEline's 16th field, engine 0.1.39+) are given as their own share of all routed experts."""