GitHub user MindFlavor created an exporter for WireGuard that collects metrics from the wg show all dump
command.
Install WireGuard Exporter
MindFlavor/prometheus_wireguard_exporter
A Prometheus exporter for WireGuard, written in Rust. - MindFlavor/prometheus_wireguard_exporter
You can either compile the exporter from source or use the cargo command to install the exporter. I opted for cargo.
apt-get update
apt-get install cargo
cargo install prometheus_wireguard_exporter
Cargo will download and install everything. Once this was done I copied the prometheus_wireguard_exporter
executable to /usr/local/bin/
. I'm not 100% positive if this is best practice, if you know a better way shoot me an email.
Once this is all done you should be able to run the exporter and it should show metrics on port 9586. curl http://localhost:9586/metrics
Create a service
[Unit]
Description=Prometheus WireGuard Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=root
Group=root
Type=simple
ExecStart=/usr/local/bin/prometheus_wireguard_exporter -n /etc/wireguard/your_config_file_here.conf
[Install]
WantedBy=multi-user.target
If you add the -n flag make sure you add the friendly name metadata to your peers.
[Peer]
# friendly_name = this is a friendly name
PublicKey = lqYcojJMsIZXMUw1heAFbQHBoKjCEaeo7M1WXDh/KWc=
AllowedIPs = 10.70.0.40/32
Visualize
Grafana Dashboard

{
"__inputs": [
{
"name": "DS_PROMETHEUS",
"label": "Prometheus",
"description": "",
"type": "datasource",
"pluginId": "prometheus",
"pluginName": "Prometheus"
}
],
"__requires": [
{
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"version": "7.3.3"
},
{
"type": "panel",
"id": "graph",
"name": "Graph",
"version": ""
},
{
"type": "datasource",
"id": "prometheus",
"name": "Prometheus",
"version": "1.0.0"
},
{
"type": "panel",
"id": "stat",
"name": "Stat",
"version": ""
},
{
"type": "panel",
"id": "table",
"name": "Table",
"version": ""
}
],
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"id": null,
"links": [],
"panels": [
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_PROMETHEUS}",
"fieldConfig": {
"defaults": {
"custom": {}
},
"overrides": []
},
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 9,
"w": 24,
"x": 0,
"y": 0
},
"hiddenSeries": false,
"id": 2,
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null",
"options": {
"alertThreshold": true
},
"percentage": false,
"pluginVersion": "7.3.3",
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "sum(idelta(wireguard_sent_bytes_total[20s])) by (interface)",
"interval": "",
"legendFormat": "{{interface}} OUT",
"refId": "A"
},
{
"expr": "- sum(idelta(wireguard_received_bytes_total[60s])) by (interface)",
"interval": "",
"legendFormat": "{{interface}} IN",
"refId": "B"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Network Usage",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "decbytes",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"datasource": "${DS_PROMETHEUS}",
"fieldConfig": {
"defaults": {
"custom": {},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "rgb(255, 255, 255)",
"value": null
}
]
},
"unit": "dateTimeFromNow"
},
"overrides": []
},
"gridPos": {
"h": 6,
"w": 7,
"x": 0,
"y": 9
},
"id": 4,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "auto",
"orientation": "auto",
"reduceOptions": {
"calcs": [
"mean"
],
"fields": "",
"values": false
},
"textMode": "auto"
},
"pluginVersion": "7.3.3",
"targets": [
{
"expr": "wireguard_latest_handshake_seconds * 1000",
"instant": true,
"interval": "",
"legendFormat": "{{interface}}",
"refId": "A"
}
],
"timeFrom": null,
"timeShift": null,
"title": "Last Handshake",
"type": "stat"
},
{
"datasource": "${DS_PROMETHEUS}",
"fieldConfig": {
"defaults": {
"custom": {
"align": null,
"filterable": false
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "job"
},
"properties": [
{
"id": "custom.width",
"value": 154
}
]
},
{
"matcher": {
"id": "byName",
"options": "public_key"
},
"properties": [
{
"id": "custom.width",
"value": 414
}
]
},
{
"matcher": {
"id": "byName",
"options": "remote_port"
},
"properties": [
{
"id": "custom.width",
"value": 121
}
]
},
{
"matcher": {
"id": "byName",
"options": "remote_ip"
},
"properties": [
{
"id": "custom.width",
"value": 121
}
]
},
{
"matcher": {
"id": "byName",
"options": "Last Check"
},
"properties": [
{
"id": "unit",
"value": "dateTimeFromNow"
}
]
}
]
},
"gridPos": {
"h": 6,
"w": 17,
"x": 7,
"y": 9
},
"id": 6,
"options": {
"showHeader": true,
"sortBy": []
},
"pluginVersion": "7.3.3",
"targets": [
{
"expr": "wireguard_latest_handshake_seconds * 1000",
"format": "table",
"instant": true,
"interval": "",
"legendFormat": "",
"refId": "A"
}
],
"timeFrom": null,
"timeShift": null,
"title": "",
"transformations": [
{
"id": "organize",
"options": {
"excludeByName": {
"Time": true,
"__name__": true,
"instance": true,
"job": true
},
"indexByName": {},
"renameByName": {
"Value": "Last Check"
}
}
}
],
"type": "table"
}
],
"refresh": "30s",
"schemaVersion": 26,
"style": "dark",
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-1h",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "WireGuard",
"uid": "-Ka00AIGz",
"version": 5
}