- Notifications
You must be signed in to change notification settings - Fork0
A simple shell script which when used with the exec plugin for collectd, will retrieve per-peer WireGuard transfer metrics for consumption by collectd.
License
snh/collectd-wireguard
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A simple shell script which when used with theexecplugin forcollectd, will retrieve per-peerWireGuardtransfer metrics for consumption bycollectd.
$ wginterface: wg0 public key: 8x0BeYAO6R2v/hKm6kNfohxf9QfQdKd3tfCPsARuemU= private key: (hidden) listening port: 51820peer: eynPhbDg/Ca9Z4Nmk37C6TAMwtdsiYIEh1OEzP5z0Es= endpoint: 172.28.128.4:51820 allowed ips: 10.0.0.2/32 latest handshake: 20 minutes, 45 seconds ago transfer: 11.35 GiB received, 57.93 MiB sentinterface: wg1 public key: 65bI/yi7hwLuuU494nfVSNASkwyIXlYGP7woVzHAq2c= private key: (hidden) listening port: 51821peer: z6xFfD7J7oVHWGRO4p3YDyOW2FYuTIZPFjDs4CshaVI= allowed ips: 10.0.1.2/32
$ COLLECTD_HOSTNAME="example-host" COLLECTD_INTERVAL=5 ./collectd-wireguard.shPUTVAL "example-host/wireguard-wg0/if_octets-eynPhbDg/Ca9Z4Nmk37C6TAMwtdsiYIEh1OEzP5z0Es=" interval=5 N:12182053116:60742952PUTVAL "example-host/wireguard-wg1/if_octets-z6xFfD7J7oVHWGRO4p3YDyOW2FYuTIZPFjDs4CshaVI=" interval=5 N:0:0
This example assumes that the script will be run as thecollectd
user, usingsudo
to runwg show all transfer
asroot
.
For security reasons, it is not recommended that you run this script directly asroot
.
To run this script as a different user, replacecollectd
in thecollectd andsudoers with the appropriate username.
These instructions may require some tweaking depending on your specificenvironment and/or operating system/distribution.
Placecollectd-wireguard.sh
in a suitable location, accessible by the userrunning this script. For this example/usr/share/collectd/
is used.
Add the following to yourcollectd.conf
, which is often located at/etc/collectd/collectd.conf
:
LoadPlugin exec<Plugin exec> Exec "collectd" "/usr/share/collectd/collectd-wireguard.sh"</Plugin>
This example executes the script as thecollectd
user.
To allow the user running the script to executewg show all transfer
, add thefollowing to yoursudoers
file usingvisudo
:
collectd ALL=(root) NOPASSWD: /usr/bin/wg show all transfer
AVagrantVagrantfile
is included which will provision two Debian Busterbased nodes withWireGuard,collectd, andcollectd-wireguard.
collectd is configured to write to/var/lib/collectd/csv/
in CSV format.
MIT LicenseCopyright (c) 2019 Steven HonsonPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.
About
A simple shell script which when used with the exec plugin for collectd, will retrieve per-peer WireGuard transfer metrics for consumption by collectd.