[SPRINT-V1][B] Гигиена: drift-детектор compose + контроль свежести бэкапов; compose приведён к живым версиям (loki, promtail, alertmanager); yandex-bridge выключен

This commit is contained in:
root committed 2026-11-05 19:53:31 +03:00
1 parent a72b7734d9
commit d18c5689b5
5 files changed
+112 -14

No files matched your search

+2 -2
View File
@@ -18,7 +18,7 @@ services:
entrypoint:
- "/agent"
loki:
image: "grafana/loki:3.2.1"
image: "grafana/loki:3.7.9"
container_name: "loki"
restart: "unless-stopped"
ports:
@@ -60,7 +60,7 @@ services:
entrypoint:
- "/bin/oauth2-proxy"
promtail:
image: "grafana/promtail:3.2.1"
image: "grafana/promtail:3.5.1"
container_name: "promtail"
restart: "unless-stopped"
network_mode: "host"
+1 -1
View File
@@ -8,7 +8,7 @@ services:
command:
- "--config.file=/etc/alertmanager/alertmanager.yml"
- "--storage.path=/alertmanager"
image: "prom/alertmanager:v0.27.0"
image: "prom/alertmanager:v0.34.1"
container_name: "alertmanager"
restart: "unless-stopped"
network_mode: "host"
+7
View File
@@ -8,3 +8,10 @@ ct:
since: "2026-11-05"
units: []
# Выключенные юниты с причиной
units_off:
"hub-yandex-bridge.service":
reason: "токен api.iot.yandex.net недействителен (HTTP 400 с 27.10), мост не может опрашивать устройства"
disabled: "2026-11-05"
to_restore: "получить новый OAuth-токен Яндекса, положить в /root/.yandex-token, systemctl enable --now"
+27 -9
View File
@@ -1,13 +1,13 @@
# Гигиенический отчёт — 2026-11-05
Проверок: 15 · находок: **19**
· high: 1 · medium: 9 · low: 5 · info: 4
Проверок: 17 · находок: **21**
· high: 1 · medium: 9 · low: 5 · info: 6
## Сводка по категориям
| Тип | Кол-во | Уровень |
|---|---|---|
| включён, но не работает | 1 | high |
| drift compose | 1 | high |
| дубль сервиса | 7 | medium |
| заготовки без запуска | 1 | medium |
| крупный потребитель RAM | 1 | medium |
@@ -15,15 +15,17 @@
| потребление RAM | 1 | info |
| мониторинг | 1 | info |
| бэкапы | 1 | info |
| бэкапы в норме | 1 | info |
| compose-паритет | 1 | info |
| docker-мусор | 1 | info |
## [HIGH] включён, но не работает
## [HIGH] drift compose
**Что:** 1 юнитов: hub-yandex-bridge.service
**Что:** CT110: 2 расхождений
**Почему:** должны работать — но лежат
**Почему:** живое состояние расходится с git — восстановление из репозитория не сработает
**Что делать:** journalctl -u <unit>, затем запустить или выключить
**Что делать:** python3 ops/scripts/check-compose-parity.py <ct> и обновить compose
## [MEDIUM] дубль сервиса
@@ -91,7 +93,7 @@
## [MEDIUM] крупный потребитель RAM
**Что:** netbox (CT103) — 850.1MiB / 4GiB, CPU 0.00%
**Что:** netbox (CT103) — 850.7MiB / 4GiB, CPU 0.00%
**Почему:** больше 800 МиБ — кандидат на оптимизацию
@@ -139,7 +141,7 @@
## [INFO] потребление RAM
**Что:** топ: netbox 850.1MiB · paperless 514.5MiB · docmost 381.9MiB · n8n 321.4MiB · homeassistant 308.9MiB · jellyfin 278.7MiB
**Что:** топ: netbox 850.7MiB · paperless 515.2MiB · docmost 382.3MiB · n8n 323MiB · homeassistant 307.4MiB · jellyfin 275.7MiB
**Почему:** лёджер: следим за ростом
@@ -161,6 +163,22 @@
**Что делать:** —
## [INFO] бэкапы в норме
**Что:** postgres (17.9 ч), matrix (16.9 ч), infra-ops (16.4 ч), offsite (15.8 ч), vzdump (15.8 ч)
**Почему:** свежесть подтверждена
**Что делать:** —
## [INFO] compose-паритет
**Что:** проверено CT: 27, с расхождениями: 1, ошибок: 0
**Почему:** соответствие репозиторию
**Что делать:** —
## [INFO] docker-мусор
**Что:** образов: 164, томов: 0, остановленных: 0
+75 -2
View File
@@ -296,10 +296,83 @@ def check_cron_hotspots():
"одновременный старт — риск пиков", "разнести по времени")
def check_compose_drift():
"""Сверка deploy/ctNNN/docker-compose.yml с живыми контейнерами."""
base = "/root/buryan-infra/deploy"
script = "/root/buryan-infra/ops/scripts/check-compose-parity.py"
if not (os.path.isdir(base) and os.path.exists(script)):
return
drift, checked, errors = [], 0, 0
for d in sorted(os.listdir(base)):
if not d.startswith("ct"):
continue
ct = d[2:]
out = sh("cd /root/buryan-infra && timeout 60 /usr/bin/python3 %s %s 2>&1 | tail -2"
% (script, ct), 90)
if not out:
errors += 1
continue
m = re.search(r"расхождений\s+(\d+)", out)
if not m:
errors += 1
continue
checked += 1
if int(m.group(1)) > 0:
drift.append("CT%s: %s расхождений" % (ct, m.group(1)))
if drift:
add("high", "drift compose", "; ".join(drift[:8]),
"живое состояние расходится с git — восстановление из репозитория не сработает",
"python3 ops/scripts/check-compose-parity.py <ct> и обновить compose")
add("info", "compose-паритет", "проверено CT: %d, с расхождениями: %d, ошибок: %d"
% (checked, len(drift), errors), "соответствие репозиторию", "—")
def check_backup_freshness():
"""Проверяет, что задания бэкапа реально отрабатывали за последние сутки."""
jobs = [
("postgres", "/var/log/buryan-hub/backups/cron-pg.log", 26),
("matrix", "/var/log/buryan-hub/backups/cron-matrix.log", 26),
("infra-ops", "/root/buryan-infra/ops/backups/backup.log", 26),
("offsite", "/var/log/buryan-hub/backups/cron-offsite.log", 30),
]
stale, ok = [], []
now = datetime.now().timestamp()
for name, path, hours in jobs:
if not os.path.exists(path):
stale.append("%s (нет лога %s)" % (name, path))
continue
age_h = (now - os.path.getmtime(path)) / 3600
if age_h > hours:
stale.append("%s (%.1f ч назад)" % (name, age_h))
else:
ok.append("%s (%.1f ч)" % (name, age_h))
# vzdump: самый свежий архив
newest = sh("ls -t /var/lib/vz/dump/*.tar.zst 2>/dev/null | head -1", 20)
if newest:
try:
age_h = (now - os.path.getmtime(newest)) / 3600
if age_h > 26:
stale.append("vzdump (%.1f ч назад)" % age_h)
else:
ok.append("vzdump (%.1f ч)" % age_h)
except Exception:
pass
else:
stale.append("vzdump (архивов не найдено)")
if stale:
add("high", "бэкапы не свежие", "; ".join(stale[:6]),
"восстановление будет из устаревших данных",
"проверить cron/логи, запустить вручную")
if ok:
add("info", "бэкапы в норме", ", ".join(ok[:6]), "свежесть подтверждена", "—")
CHECKS = [check_duplicates, check_units, check_failed_units, check_onboot, check_ram,
check_monitoring, check_disk, check_ct_disk, check_certs, check_backups,
check_docker_waste, check_logs, check_secrets_perms, check_swap_pressure,
check_cron_hotspots]
check_backup_freshness, check_compose_drift, check_docker_waste, check_logs,
check_secrets_perms, check_swap_pressure, check_cron_hotspots]
def main():