[PRISM] Add read-only prism_* summary endpoint

This commit is contained in:
root committed 2026-11-23 20:24:13 +03:00
1 parent 420566814d
commit b585185af2
1 file changed
+32
+32
View File
@@ -11,6 +11,7 @@ import re
import glob
import yaml
import socketserver
import subprocess
import time
import urllib.parse
from http.server import BaseHTTPRequestHandler
@@ -1667,6 +1668,35 @@ def save_project(payload):
return {"ok": True, "id": pid}
def prism_summary():
"""Read-only сводка model-centric базы Prism на PostgreSQL 151."""
try:
pw = open("/root/.pg-superuser-pass", encoding="utf-8").read().strip()
env = dict(os.environ)
env["PGPASSWORD"] = pw
sql = (
"select json_build_object("
"'models',(select count(*) from prism.models),"
"'source_ok',(select count(*) from prism.models where status='source_ok'),"
"'needs_source',(select count(*) from prism.models where status='needs_source'),"
"'sources',(select count(*) from prism.sources),"
"'datasheets',(select count(*) from prism.sources where doc_type='datasheet'),"
"'specs',(select count(*) from prism.specs),"
"'evidence',(select count(*) from prism.evidence)"
")::text"
)
out = subprocess.check_output(
["/usr/bin/psql", "-w", "-h", "192.168.1.151", "-U", "postgres",
"-d", "rag", "-t", "-A", "-c", sql],
env=env, text=True, timeout=15)
d = json.loads(out.strip())
d["ok"] = True
return d
except Exception as e:
return {"ok": False, "error": str(e)[:200]}
class H(BaseHTTPRequestHandler):
def _out(self, obj, code=200, ctype="application/json; charset=utf-8"):
body = obj if isinstance(obj, bytes) else json.dumps(obj, ensure_ascii=False).encode()
@@ -1693,6 +1723,8 @@ class H(BaseHTTPRequestHandler):
return self._out(open(f, encoding="utf-8").read().encode(), ctype="text/html; charset=utf-8")
if p in ("/health", "/api/health"):
return self._out({"ok": True, "service": "combine-web", "devices": len(D.devices)})
if p == "/api/prism/summary":
return self._out(prism_summary())
if p == "/api/stats":
return self._out({"devices": len(D.devices),
"edges": sum(len(v) for v in D.edges.values()),