Skip to content

monitoring: derive nginx_exporter_listen from per-host wg_ip#39

Merged
findias merged 1 commit into
mainfrom
fix/monitoring-nginx-exporter-per-host-listen
May 6, 2026
Merged

monitoring: derive nginx_exporter_listen from per-host wg_ip#39
findias merged 1 commit into
mainfrom
fix/monitoring-nginx-exporter-per-host-listen

Conversation

@findias
Copy link
Copy Markdown
Contributor

@findias findias commented May 6, 2026

Why

nginx_exporter_listen defaulted to a hardcoded 10.10.0.2:9113 — the first RU's WG address. With multiple RUs in groups['ru'] (live as of 2026-05-06), the second RU tried to bind to an address not assigned to its interface and entered a systemd restart loop:

HTTP server failed: listen tcp 10.10.0.2:9113: bind: cannot assign requested address

Fix

Derive listen address from per-host wg_ip with the same default(wg_ru_ip) fallback that scrape configs and node_exporter already use:

nginx_exporter_listen: "{{ hostvars[inventory_hostname].wg_ip | default(wg_ru_ip) }}:9113"

vmagent's vmagent-scrape.yml.j2 already iterates groups['ru'] with the same expression, so listening + scraping stay in lockstep on each RU.

Behaviour

  • vm_my_ru (wg_ip=10.10.0.2) → listen 10.10.0.2:9113 (unchanged)
  • vm_my_ru2 (wg_ip=10.10.0.3) → listen 10.10.0.3:9113 (was broken)
  • future RUs auto-correct from their inventory entry.

Test plan

  • Re-deployed on vm_my_ru2: service goes from activating (restart loop) to active, port binds, metrics return.
  • EU vmagent picks up new instance via existing groups['ru'] loop, pushes to VictoriaMetrics.
  • VM query confirms up{job="nginx-vm_my_ru2", instance="5.8.50.41"} reports.
  • Reviewer note: vm_my_ru continues to work because wg_ip: 10.10.0.2 in inventory matches the previous hardcoded default — the new expression resolves to the same value for it.

The default `nginx_exporter_listen: "10.10.0.2:9113"` hardcoded the
first RU's WG address. With multiple RUs in groups['ru'] (live as of
2026-05-06), the second RU tried to bind 10.10.0.2:9113 — an address
not assigned to its interface — and entered a systemd restart loop:

  HTTP server failed: listen tcp 10.10.0.2:9113: bind: cannot
  assign requested address

vmagent's scrape_configs already uses
`hostvars[h].wg_ip | default(wg_ru_ip)` per-host (vmagent-scrape.yml.j2),
and node_exporter's listen address derives the same way. Bring
nginx_exporter into line with that pattern so a fresh role apply on
any RU produces a unit file that binds the local WG IP.

Behaviour:
* vm_my_ru (wg_ip=10.10.0.2)    → listen 10.10.0.2:9113   (unchanged)
* vm_my_ru2 (wg_ip=10.10.0.3)   → listen 10.10.0.3:9113   (was broken)
* future RUs auto-correct from inventory entry.

Tested by re-deploying on vm_my_ru2: service active, port bound,
metrics flow to vmagent → VictoriaMetrics. Grafana dashboards
already group by instance label so multi-RU panels populate
automatically.

Signed-off-by: findias <findias@gmail.com>
@findias findias merged commit 6862639 into main May 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant