Метрики /metrics для центрального Prometheus + генерация scrape-таргетов

--metrics-port (0.0.0.0, в отличие от --health-port — тот 127.0.0.1-only)
отдаёт netrunner_connections_active/total, netrunner_auth_validate_duration_seconds,
netrunner_auth_failures_total, netrunner_circuit_breaker_open. Тот же
hand-rolled HTTP-паттерн, что и health.rs — без HTTP-фреймворка ради
одного эндпоинта.

scripts/generate-prometheus-targets.mjs генерит список scrape-таргетов
из nodes.json — job update-observability-targets в deploy.yml гоняет
его при каждом деплое нод и заливает на VPS с данными
(netrunner-data/observability/targets/nodes.json), чтобы центральный
Prometheus не терял из виду ноды без ручной правки конфига.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-09 23:21:26 +07:00
parent fafd573a28
commit cfcb1afcec
11 changed files with 367 additions and 13 deletions
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/env node
// Генерит targets-файл для Prometheus file_sd_configs (см.
// netrunner-data/observability/prometheus.yml, job "netrunner-proxy-nodes")
// из nodes.json этого репозитория — список нод меняется независимо от
// прод-конфига Prometheus, руками синхронизировать его на каждый деплой
// ноды неудобно и хрупко.
//
// Порт метрик у всех нод одинаковый (9093 — см. server/netrunner-server.service,
// templates/init_node.sh в netrunner-backend, .gitea/workflows/deploy.yml
// здесь же), меняется только host — поэтому в самом nodes.json отдельного
// поля под него нет.
//
// Использование: node scripts/generate-prometheus-targets.mjs nodes.json > targets.json
import { readFileSync } from "node:fs";
const METRICS_PORT = 9093;
const [, , nodesPath] = process.argv;
if (!nodesPath) {
console.error("Использование: generate-prometheus-targets.mjs <nodes.json>");
process.exit(1);
}
const nodes = JSON.parse(readFileSync(nodesPath, "utf-8"));
const targets = nodes
.filter((n) => !n.host?.startsWith("CHANGE_ME"))
.map((n) => ({
targets: [`${n.host}:${METRICS_PORT}`],
labels: { node: n.name },
}));
process.stdout.write(JSON.stringify(targets, null, 2) + "\n");