[SPRINT-V1][B] Реестр: SSO-детект по портам прокси, 208 зависимостей, стоимость 113 сервисов

This commit is contained in:
root committed 2026-11-06 11:05:44 +03:00
1 parent 8e079d2879
commit 108a53b9db
3 files changed
+851 -7

No files matched your search

+2 -2
View File
@@ -1,6 +1,6 @@
# Реестр инфраструктуры (единый источник правды)
_Обновлено: 2026-11-06T11:01:08_
_Обновлено: 2026-11-06T11:05:43_
| Сущность | Количество |
|---|---|
@@ -30,7 +30,7 @@ _Обновлено: 2026-11-06T11:01:08_
| grafana.buryans.ru | — | нет | нет | host |
| grocy.buryans.ru | 192.168.1.110:9284 | да | нет | host |
| headscale.buryans.ru | 100.64.0.2:8443 | да | нет | host |
| home.buryans.ru | 192.168.1.106:9130 | да | нет | host |
| home.buryans.ru | 192.168.1.106:9130 | да | да | host |
| homebox.buryans.ru | — | нет | нет | host |
| hub.buryans.ru | 192.168.1.10:9120/me | да | нет | host |
| immich.buryans.ru | 192.168.1.104:2283 | да | нет | host |
+798 -2
View File
File diff suppressed because it is too large. Load diff
+51 -3
View File
@@ -85,6 +85,29 @@ def _blocks(text):
return blocks
def costs(hostlist):
"""RAM по контейнерам (docker stats, один вызов на хост)."""
out = {}
for h in hostlist:
if h["status"] != "running":
continue
if h["type"] == "lxc":
cmd = "pct exec %s -- " % h["vmid"]
else:
cmd = ""
raw = sh(cmd + "docker stats --no-stream --format '{{.Name}}|{{.MemUsage}}' 2>/dev/null", 90)
for ln in raw.splitlines():
f = ln.split("|")
if len(f) < 2:
continue
m = re.match(r"([\d.]+)([KMG]iB)", f[1].strip())
if m:
v = float(m.group(1))
mb = v / 1024 if m.group(2) == "KiB" else (v * 1024 if m.group(2) == "GiB" else v)
out[f[0]] = round(mb, 1)
return out
def domains():
"""Домены из nginx: server_name + proxy_pass (хост и VPS)."""
seen, out = set(), []
@@ -101,7 +124,7 @@ def domains():
ups = [u for u in re.findall(r"proxy_pass\s+https?://([^;\s]+)", block)
if "oauth2" not in u]
ssl = "ssl_certificate" in block
auth = "auth_request" in block
auth = ("auth_request" in block) or ("oauth2" in block.lower())
for n in names[0].split():
n = n.strip()
if not n or n in ("_", "localhost") or "$" in n or n in seen:
@@ -112,16 +135,40 @@ def domains():
return sorted(out, key=lambda x: x["domain"])
def dependencies(hosts_list, services_list, domains_list):
"""Рёбра: хост содержит сервис; домен проксируется на сервис."""
edges = []
for sv in services_list:
edges.append({"from": sv["host"], "to": sv["name"], "kind": "runs"})
for d in domains_list:
up = (d.get("upstream") or "").split("/")[0]
if not up:
continue
target = None
for sv in services_list:
if any(":%d" % p in up for p in (sv.get("ports") or [])):
target = sv["name"]
break
if not target and up:
target = up
edges.append({"from": "domain:%s" % d["domain"], "to": target or up, "kind": "proxy"})
return edges
def main():
os.makedirs(OUT, exist_ok=True)
h = hosts()
s = services(h)
d = domains()
c = costs(h)
e = dependencies(h, s, d)
for sv in s:
sv["ram_mb"] = c.get(sv["name"])
import yaml
reg = {"version": 2,
"generated": datetime.now().isoformat(timespec="seconds"),
"counts": {"hosts": len(h), "services": len(s), "domains": len(d)},
"hosts": h, "services": s, "domains": d}
"counts": {"hosts": len(h), "services": len(s), "domains": len(d), "dependencies": len(e)},
"hosts": h, "services": s, "domains": d, "dependencies": e}
path = os.path.join(OUT, "registry.yaml")
with open(path, "w", encoding="utf-8") as f:
yaml.safe_dump(reg, f, allow_unicode=True, sort_keys=False, width=200)
@@ -145,6 +192,7 @@ def main():
print("хостов: %d | сервисов: %d | доменов: %d" % (len(h), len(s), len(d)))
print("домены с SSO: %d | без SSO: %d"
% (sum(1 for x in d if x["sso"]), sum(1 for x in d if not x["sso"])))
print("зависимостей: %d | сервисов со стоимостью: %d" % (len(e), len(c)))
if __name__ == "__main__":