1803833b50
- hub/dashboards/unibus-cluster.json: dashboard 'unibus — Cluster' (carpeta Fleet, datasource VictoriaMetrics): nodos up, cluster_size, nodos caídos, posture homogénea segura, matriz de posture por nodo (enforce/acl/tls/cluster/store-kv), latencia de scrape y tabla de estado por nodo. Panel meta-leader preparado (n/d sin métricas NATS). - hub/deploy_unibus_exporter.sh: compila el exporter, sube binario + CA del cluster a magnus e instala el servicio systemd apuntando a la VictoriaMetrics local. El exporter (apps/unibus_exporter, sub-repo Gitea propio) compone parse_unibus_health + format_prom_exposition + push_prom_remote del registry. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
85 lines
3.0 KiB
Bash
Executable File
85 lines
3.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Despliega unibus_exporter en un nodo (por defecto magnus, el hub) como servicio
|
|
# systemd. El exporter sondea el /healthz de los 3 nodos del cluster unibus por
|
|
# IP pública y empuja métricas de estado/posture a la VictoriaMetrics local.
|
|
#
|
|
# Uso: ./deploy_unibus_exporter.sh [node_name] [ssh_host]
|
|
# node_name : nombre lógico del host donde corre el exporter (default magnus)
|
|
# ssh_host : alias SSH de ese host (default om)
|
|
#
|
|
# Requisitos:
|
|
# - Go instalado localmente (compila el binario amd64).
|
|
# - La CA del cluster unibus en projects/message_bus/apps/unibus/deploy/tls/ca.crt
|
|
# (o cluster/out/<n>/ca.crt — son idénticas).
|
|
# - sudo -n (sin password) en el host remoto.
|
|
set -euo pipefail
|
|
|
|
NODE="${1:-magnus}"
|
|
HOST="${2:-om}"
|
|
|
|
ROOT="$(cd "$(dirname "$0")/.." && pwd)" # projects/fleet_monitoring
|
|
APP="$ROOT/apps/unibus_exporter"
|
|
CA="$ROOT/../message_bus/apps/unibus/deploy/tls/ca.crt"
|
|
HUB="http://127.0.0.1:8428/api/v1/import/prometheus" # VM local en el hub (sin auth)
|
|
|
|
[ -f "$CA" ] || { echo "ERROR: falta la CA del cluster en $CA"; exit 1; }
|
|
|
|
echo ">> compilando unibus_exporter (linux/amd64)"
|
|
mkdir -p "$APP/dist"
|
|
( cd "$APP" && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o dist/unibus_exporter_amd64 . )
|
|
BIN="$APP/dist/unibus_exporter_amd64"
|
|
|
|
echo ">> subiendo binario + CA a $HOST"
|
|
scp -q -o BatchMode=yes "$BIN" "$HOST:/tmp/unibus_exporter"
|
|
scp -q -o BatchMode=yes "$CA" "$HOST:/tmp/unibus_ca.crt"
|
|
|
|
echo ">> instalando servicio en $NODE ($HOST)"
|
|
ssh -o BatchMode=yes "$HOST" "NODE='$NODE' HUB='$HUB' bash -s" <<'OUTER'
|
|
set -e
|
|
sudo -n mkdir -p /opt/unibus-exporter /etc/unibus-exporter
|
|
sudo -n mv /tmp/unibus_exporter /opt/unibus-exporter/unibus_exporter
|
|
sudo -n chmod 755 /opt/unibus-exporter/unibus_exporter
|
|
sudo -n mv /tmp/unibus_ca.crt /etc/unibus-exporter/ca.crt
|
|
sudo -n chmod 644 /etc/unibus-exporter/ca.crt
|
|
sudo -n tee /etc/unibus-exporter/unibus.json >/dev/null <<JSON
|
|
{
|
|
"nodes": [
|
|
{ "name": "magnus", "url": "https://135.125.201.30:8470/healthz" },
|
|
{ "name": "homer", "url": "https://141.94.69.66:8470/healthz" },
|
|
{ "name": "datardos", "url": "https://51.91.100.142:8470/healthz" }
|
|
],
|
|
"ca_cert_path": "/etc/unibus-exporter/ca.crt",
|
|
"hub_url": "${HUB}",
|
|
"user": "",
|
|
"pass": "",
|
|
"interval_sec": 15,
|
|
"timeout_sec": 8,
|
|
"labels": { "job": "unibus_exporter" }
|
|
}
|
|
JSON
|
|
sudo -n chmod 600 /etc/unibus-exporter/unibus.json
|
|
sudo -n tee /etc/systemd/system/unibus-exporter.service >/dev/null <<'UNIT'
|
|
[Unit]
|
|
Description=unibus cluster exporter (fleet_monitoring)
|
|
After=network-online.target
|
|
Wants=network-online.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
ExecStart=/opt/unibus-exporter/unibus_exporter -config /etc/unibus-exporter/unibus.json
|
|
Restart=always
|
|
RestartSec=10
|
|
NoNewPrivileges=true
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
UNIT
|
|
sudo -n systemctl daemon-reload
|
|
sudo -n systemctl enable unibus-exporter >/dev/null 2>&1
|
|
sudo -n systemctl restart unibus-exporter
|
|
sleep 3
|
|
echo -n "status: "; systemctl is-active unibus-exporter
|
|
OUTER
|
|
|
|
echo ">> $NODE: unibus_exporter desplegado"
|