A Prometheus exporter for WireGuard, written in Rust. This tool exports the wg show all dump (or wg show <interface> dump if you specify a config file) results in a format that Prometheus can understand. The exporter is very light on your server resources, both in terms of memory and CPU usage. It's also built for Docker for the following CPU architectures: amd64, 386, arm64, armv7 and armv6.

wireguard_latest_handshake_delay_seconds. Thanks to mmahacek for the idea.[WireGuardPeer] rather than [Peer]). Thanks to mbonino for the PR (see https://github.com/MindFlavor/prometheus_wireguard_exporter/pull/92).friendly_name. Thanks to Steven Wood for finding the bug in #82.3.6.0 the exporter takes fallback configuration values from the environment variables. Thanks to j_r0dd for the idea. This changes how the exporter evaluates the command line parameters: make sure to consult the documentation on how to convert your command line to the new format. Basically every switch (for example verbose -v) not expect values, either true or false. This is necessary because there is no way to discriminate between an empty environment variable and one that has not been set.friendly_json tag. Entries prepended with the friendly_json tag will output all the entries in the specificed json as Prometheus attributes. Thanks to DrProxyProSupport for the idea.sudo to the wg command. This allows to run the exporter as a non root user (although sudoer without password). Thanks to Jonas Seydel for the idea.sed -i 's/#/# friendly_name=/' peers.conf. Please make sure to do a backup before using it!-i parameter multiple times. Note the not specifying the interface is equivalent to specifying every one of them (the exporter will pass the all parameter to wg show command).-n flag) the program would infer the interface name from the file name. Now the two items are decoupled: you need to specify the file name (with -n) and the interface name (with -i) separately. Thank you Vincent Debergue for helping with this (see issue #22). Upgrading from 3.2.4: Please note that the -n flag no longer infer automatically the interface name from the file name. We now have the -i parameter for that. In order to keep the previous behaviour (if you use the -n flag) please add the -i flag to the command line arguments as well. For example, if you had prometheus_wireguard_exporter -n /etc/wireguard/wg0.conf you must specify prometheus_wireguard_exporter -n /etc/wireguard/wg0.conf -i wg0 to keep the same behaviour.allowed_ips) along with their subnets. The second one is to create a pair of labels for each allowed ip/subnet pair (called allowed_ip_0/allowed_subnet_0, allowed_ip_1/allowed_subnet_1 and so on for every allowed ip). The default if the single label mode but you can enable the second mode by specifying the -s switch at startup. Thank you Toon Schoenmakers for this solution (see issue #8).Coming soon, subcribe to #59
Download and run the container with:
sh
docker run -d --net=host --cap-add=NET_ADMIN --name wgexporter mindflavor/prometheus-wireguard-exporter
⚠️ If you encounter time issues on your 32 bit operating system, check this
Check it's up by visiting http://localhost:9586/metrics
You can then update the image with
docker pull mindflavor/prometheus_wireguard_exporter
Or use a tagged image such as :3.5.1.
If your host has an amd64 or 686 CPU, you can also build the Docker image from source (you need git) with:
docker build -t mindflavor/prometheus_wireguard_exporter https://github.com/MindFlavor/prometheus_wireguard_exporter.git#master
wg accessible in your path. The tool will call wg show <interface(s)>|all dump and of course will fail if the wg executable is not found.git installedClone the repository with
sh
git clone https://github.com/MindFlavor/prometheus_wireguard_exporter.git
cd prometheus_wireguard_exporter
Compile the program with
sh
cargo install --path .
💁 If you encounter errors, please try updating your rust installation with rustup update.
The code should compile with any relatively recent, 2018-compliant rustc version.
As a frame of reference, the last release was built using the Rust Docker image using rustc 1.53.0 (53cb7b09b 2021-06-17).
Run the program
sh
./prometheus_wireguard_exporter
Check it's up by visiting http://localhost:9586/metrics
Start the binary with -h to get the complete syntax. The parameters are below.
❗Important ❗: since 3.6.0, every parameter requires a value. In other words, even the -v (verbose) parameter requires true or false after it. Passing a parameter without value (for example -v) is the same of not passing the parameter at all: the default value will be used instead (in the case of the verbose option, it means false).
For example, if you want to enable the verbose mode and enable the prepend sudo option you would use the following command line:
prometheus_wireguard_exporter -a true -v true <...>
| Parameter | Env | Mandatory | Valid values | Default | Accepts multiple occurrences? | Description |
|---|---|---|---|---|---|---|
-v |
PROMETHEUS_WIREGUARD_EXPORTER_VERBOSE_ENABLED |
No | true or false |
false |
No | Enable verbose mode. |
-a |
PROMETHEUS_WIREGUARD_EXPORTER_PREPEND_SUDO_ENABLED |
No | true or false |
false |
No | Prepends sudo to wg commands. |
-l |
PROMETHEUS_WIREGUARD_EXPORTER_ADDRESS |
No | Any valid IP address | 0.0.0.0 |
No | Specify the service address. This is the address your Prometheus instance should point to. |
-p |
PROMETHEUS_WIREGUARD_EXPORTER_PORT |
No | Any valid port number | 9586 |
No | Specify the service port. This is the port your Prometheus instance should point to. |
-n |
PROMETHEUS_WIREGUARD_EXPORTER_CONFIG_FILE_NAMES |
No | Path to the wireguard configuration file | Yes | This flag adds the friendly_name attribute or the friendly_json attributes to the exported entries. See Friendly tags for more details. Multiple files are allowed (they will be merged as a single file in memory so avoid duplicates). | |
-s |
PROMETHEUS_WIREGUARD_EXPORTER_SEPARATE_ALLOWED_IPS_ENABLED |
No | true or false |
false |
No | Enable the allowed ip + subnet split mode for the labels. |
-r |
PROMETHEUS_WIREGUARD_EXPORTER_EXPORT_REMOTE_IP_AND_PORT_ENABLED |
No | true or false |
false |
No | Exports peer's remote ip and port as labels (if available). |
-i |
PROMETHEUS_WIREGUARD_EXPORTER_INTERFACES |
No | Your interface name(s) | all |
Yes | Specifies the interface(s) passed to the wg show <interface> dump parameter. Multiple parameters are allowed. |
-d |
EXPORT_LATEST_HANDSHAKE_DELAY |
No | true or false |
false |
No | Adds the wireguard_latest_handshake_delay_seconds metric that automatically calculates the seconds passed since the last handshake. |
Keep in mind that command line values take precedence over environment variables.
Once started, the tool will listen on the specified port (or the default one, 9586, if not specified) and return a Prometheus valid response at the url /metrics. So to check if the tool is working properly simply browse the http://localhost:9586/metrics (or whichever port you choose).
Starting from version 3.5 you can instruct the exporter to append a friendly name or a friendly_json to the exported entries. This can make the output more understandable than using the public keys. For example this is the standard output:
```ebnf
wireguard_sent_bytes_total{interface="wg0",public_key="2S7mA0vEMethCNQrJpJKE81/JmhgtB+tHHLYQhgM6kk=",allowed_ips="10.70.0.2/32,10.70.0.66/32"} 3208804 wireguard_sent_bytes_total{interface="wg0",public_key="qnoxQoQI8KKMupLnSSureORV0wMmH7JryZNsmGVISzU=",allowed_ips="10.70.0.3/32"} 0 wireguard_sent_bytes_total{interface="wg0",public_key="L2UoJZN7RmEKsMmqaJgKG0m1S2Zs2wd2ptAf+kb3008=",allowed_ips="10.70.0.4/32"} 0 wireguard_sent_bytes_total{interface="wg0",public_key="MdVOIPKt9K2MPj/sO2NlWQbOnFJ6L/qX80mmhQwsUlA=",allowed_ips="10.70.0.50/32"} 0 wireguard_sent_bytes_total{interface="wg0",p
$ claude mcp add prometheus_wireguard_exporter \
-- python -m otcore.mcp_server <graph>