MindFlavor / prometheus_wireguard_exporter

A Prometheus exporter for WireGuard, written in Rust.

Home Page:https://mindflavor.github.io/prometheus_wireguard_exporter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support multiple IP addreses

schoentoon opened this issue · comments

I have my wireguard configured to allow for multiple ip addresses per peer (generally ipv4 and ipv6). This is simply done like this

[Peer]
PublicKey = <snip>
AllowedIPs = 10.0.0.2/32, fd86:ea04:::4/128

However the eventual prometheus labels don't seem to pick up on this all too well. As I get the following labels:
wireguard_sent_bytes_total{inteface="wg0", public_key="<snip>", local_ip="10.0.0.2", local_subnet="32,fd86:ea04:::2"}

It seems to me that it is doing a simple split on the / and just uses the entire output after that as the local subnet.

You are indeed right, I haven't considered the possibility of allowing multiple IP addresses 🤦‍♂️ . I can fix this but I do not know how to express multiple IPs as Prometheus label(s). Should we drop the local_subnet label and replace local_ip with a simpler allowed_ips?
Alternatively we can have local_ip_1, local_subnet_1, local_ip_2, local_subnet_2, and so on but it's ugly.

@schoentoon what do you think we should do? I'm partial for the first approach.

I have a working solution based on the second approach. Please check out if it solves your problem!

The second approach seems better for users with only one or two ip addresses, but the first option would be better for people with a lot of ip addresses. Maybe make it configurable?
Also, while looking at this ticket again I noticed that the first label is called inteface rather than interface, thought this could have been a copy paste failure on my end. Turns out it isn't, may want to fix that too :)

Makes perfect sense. I will implement the second approach behind a startup flag.
I will also correct the inteface :D

ok in #9 I've implemented your suggestions. Let me know if it's ok by you!

Deployed it on my infrastructure and instantly looks a lot better. I'll have to tweak my grafana dashboards a bit now, but that's just a detail 😅
Thanks for the quick fixing :)