Add Prometheus metrics: /metrics, node_exporter and a page for it

The web UI serves the router's own state at /metrics (token needed);
router.metrics.nodeExporter runs node_exporter for the machine's and opens
its port only to the zones named. The Prometheus page edits those settings
and shows the scrape configuration.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 11:30:02 +01:00
co-authored by Claude Sonnet 5.5
parent 32bf0d5fde
commit 6e23d183fc
13 changed files with 672 additions and 1 deletions
+48
View File
@@ -0,0 +1,48 @@
{{define "content"}}
<div class="cols">
{{with .Data}}
{{$e := .Errors}}{{$f := .Form}}
<section>
<h2>The router's state</h2>
<p>The web UI serves the router's own state for Prometheus at <code>https://{{.Host}}/metrics</code>: the uplink and its
pings, pending changes, DHCP leases, WireGuard peers and the certificate's expiry. It needs a token (any access)
from the <a href="/tokens">API access</a> page; nothing is switched on here.</p>
<pre class="log">scrape_configs:
- job_name: router
scheme: https
tls_config:
insecure_skip_verify: true # or ca_file, if the certificate is not self-signed
authorization:
credentials: rtr_…
static_configs:
- targets: ['{{.Host}}']</pre>
</section>
<form method="post" action="/prometheus">
<input type="hidden" name="csrf" value="{{$.CSRF}}">
<fieldset>
<legend>The machine (node_exporter)</legend>
<label class="inline"><input type="checkbox" name="enabled" {{if $f.Enabled}}checked{{end}}> Run node_exporter: CPU, memory, disks, network interfaces and systemd units</label>
<label>Port <input name="port" value="{{$f.Port}}" size="6" inputmode="numeric"></label>
{{with index $e "port"}}<p class="field-error">{{.}}</p>{{end}}
<p>Open to these zones (the port is closed to every other zone and to the internet):</p>
{{range .Zones}}<label class="inline"><input type="checkbox" name="zone" value="{{.Name}}" {{if .Checked}}checked{{end}}> {{.Name}}</label>
{{else}}<p class="muted">There is no zone yet: add a LAN or a tunnel first.</p>{{end}}
{{with index $e "zones"}}<p class="field-error">{{.}}</p>{{end}}
<p class="hint">With no zone chosen, node_exporter runs but only the router itself can read it. It listens on every address;
the firewall is what keeps others out. Saving does not change the router: apply the settings afterwards.</p>
</fieldset>
<button>Save</button>
</form>
{{if $f.Enabled}}
<section>
<h2>Scrape it</h2>
<pre class="log"> - job_name: router-node
static_configs:
- targets: ['{{.Target}}']</pre>
</section>
{{end}}
{{end}}
</div>
{{end}}