This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add wireguard collector (#744)
- Loading branch information
Showing
11 changed files
with
1,015 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# netdata go.d.plugin configuration for wireguard | ||
# | ||
# This file is in YAML format. Generally the format is: | ||
# | ||
# name: value | ||
# | ||
# There are 2 sections: | ||
# - GLOBAL | ||
# - JOBS | ||
# | ||
# | ||
# [ GLOBAL ] | ||
# These variables set the defaults for all JOBs, however each JOB may define its own, overriding the defaults. | ||
# | ||
# The GLOBAL section format: | ||
# param1: value1 | ||
# param2: value2 | ||
# | ||
# Currently supported global parameters: | ||
# - update_every | ||
# Data collection frequency in seconds. Default: 1. | ||
# | ||
# - autodetection_retry | ||
# Re-check interval in seconds. Attempts to start the job are made once every interval. | ||
# Zero means not to schedule re-check. Default: 0. | ||
# | ||
# - priority | ||
# Priority is the relative priority of the charts as rendered on the web page, | ||
# lower numbers make the charts appear before the ones with higher numbers. Default: 70000. | ||
# | ||
# | ||
# [ JOBS ] | ||
# JOBS allow you to collect values from multiple sources. | ||
# Each source will have its own set of charts. | ||
# | ||
# IMPORTANT: | ||
# - Parameter 'name' is mandatory. | ||
# - Jobs with the same name are mutually exclusive. Only one of them will be allowed running at any time. | ||
# | ||
# This allows autodetection to try several alternatives and pick the one that works. | ||
# Any number of jobs is supported. | ||
# | ||
# The JOBS section format: | ||
# | ||
# jobs: | ||
# - name: job1 | ||
# param1: value1 | ||
# param2: value2 | ||
# | ||
# - name: job2 | ||
# param1: value1 | ||
# param2: value2 | ||
# | ||
# - name: job2 | ||
# param1: value1 | ||
# | ||
# [ JOB defaults ]: | ||
# charts: | ||
# num: 1 | ||
# dimensions: 3 | ||
# | ||
# | ||
# [ JOB mandatory parameters ]: | ||
# No parameters | ||
# | ||
# ------------------------------------------------MODULE-CONFIGURATION-------------------------------------------------- | ||
|
||
# update_every: 1 | ||
# autodetection_retry: 0 | ||
# priority: 70000 | ||
|
||
jobs: | ||
- name: wireguard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!-- | ||
title: "WireGuard monitoring with Netdata" | ||
description: "Monitor WireGuard VPN network interfaces and peers traffic." | ||
custom_edit_url: https://github.com/netdata/go.d.plugin/edit/master/modules/wireguard/README.md | ||
sidebar_label: "WireGuard" | ||
--> | ||
|
||
# WireGuard monitoring with Netdata | ||
|
||
[WireGuard](https://www.wireguard.com/) is an extremely simple yet fast and modern VPN that utilizes state-of-the-art | ||
cryptography. | ||
|
||
This module monitors WireGuard VPN network interfaces and peers traffic. | ||
|
||
## Requirements | ||
|
||
- Grant `CAP_NET_ADMIN` capability to `go.d.plugin`. | ||
|
||
```bash | ||
sudo setcap CAP_NET_ADMIN+epi <INSTALL_PREFIX>/usr/libexec/netdata/plugins.d/go.d.plugin | ||
``` | ||
|
||
## Metrics | ||
|
||
All metrics have "wireguard." prefix. | ||
|
||
| Metric | Scope | Dimensions | Units | | ||
|---------------------------|:------:|:-----------------:|:-------:| | ||
| device_peers | device | peers | peers | | ||
| device_network_io | device | receive, transmit | B/s | | ||
| peer_network_io | peer | receive, transmit | B/s | | ||
| peer_latest_handshake_ago | peer | time | seconds | | ||
|
||
## Configuration | ||
|
||
No configuration needed. | ||
|
||
## Troubleshooting | ||
|
||
To troubleshoot issues with the `wireguard` collector, run the `go.d.plugin` with the debug option enabled. The output | ||
should give you clues as to why the collector isn't working. | ||
First, navigate to your plugins' directory, usually at `/usr/libexec/netdata/plugins.d/`. If that's not the case on your | ||
system, open `netdata.conf` and look for the setting `plugins directory`. Once you're in the plugin's directory, switch | ||
to the `netdata` user. | ||
```bash | ||
cd /usr/libexec/netdata/plugins.d/ | ||
sudo -u netdata -s | ||
``` | ||
You can now run the `go.d.plugin` to debug the collector: | ||
```bash | ||
./go.d.plugin -d -m wireguard | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
package wireguard | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/netdata/go.d.plugin/agent/module" | ||
) | ||
|
||
const ( | ||
prioDeviceNetworkIO = module.Priority + iota | ||
prioDevicePeers | ||
prioPeerNetworkIO | ||
prioPeerLatestHandShake | ||
) | ||
|
||
var ( | ||
deviceChartsTmpl = module.Charts{ | ||
deviceNetworkIOChartTmpl.Copy(), | ||
devicePeersChartTmpl.Copy(), | ||
} | ||
|
||
deviceNetworkIOChartTmpl = module.Chart{ | ||
ID: "device_%s_network_io", | ||
Title: "Device traffic", | ||
Units: "B/s", | ||
Fam: "device traffic", | ||
Ctx: "wireguard.device_network_io", | ||
Type: module.Area, | ||
Priority: prioDeviceNetworkIO, | ||
Dims: module.Dims{ | ||
{ID: "device_%s_receive", Name: "receive", Algo: module.Incremental}, | ||
{ID: "device_%s_transmit", Name: "transmit", Algo: module.Incremental, Mul: -1}, | ||
}, | ||
} | ||
devicePeersChartTmpl = module.Chart{ | ||
ID: "device_%s_peers", | ||
Title: "Device peers", | ||
Units: "peers", | ||
Fam: "device peers", | ||
Ctx: "wireguard.device_peers", | ||
Priority: prioDevicePeers, | ||
Dims: module.Dims{ | ||
{ID: "device_%s_peers", Name: "peers"}, | ||
}, | ||
} | ||
) | ||
|
||
var ( | ||
peerChartsTmpl = module.Charts{ | ||
peerNetworkIOChartTmpl.Copy(), | ||
peerLatestHandShakeChartTmpl.Copy(), | ||
} | ||
|
||
peerNetworkIOChartTmpl = module.Chart{ | ||
ID: "peer_%s_network_io", | ||
Title: "Peer traffic", | ||
Units: "B/s", | ||
Fam: "peer traffic", | ||
Ctx: "wireguard.peer_network_io", | ||
Type: module.Area, | ||
Priority: prioPeerNetworkIO, | ||
Dims: module.Dims{ | ||
{ID: "peer_%s_receive", Name: "receive", Algo: module.Incremental}, | ||
{ID: "peer_%s_transmit", Name: "transmit", Algo: module.Incremental, Mul: -1}, | ||
}, | ||
} | ||
peerLatestHandShakeChartTmpl = module.Chart{ | ||
ID: "peer_%s_latest_handshake_ago", | ||
Title: "Peer time elapsed sine the latest handshake", | ||
Units: "seconds", | ||
Fam: "peer latest handshake", | ||
Ctx: "wireguard.peer_latest_handshake_ago", | ||
Priority: prioPeerLatestHandShake, | ||
Dims: module.Dims{ | ||
{ID: "peer_%s_latest_handshake_ago", Name: "time"}, | ||
}, | ||
} | ||
) | ||
|
||
func newDeviceCharts(device string) *module.Charts { | ||
charts := deviceChartsTmpl.Copy() | ||
|
||
for _, c := range *charts { | ||
c.ID = fmt.Sprintf(c.ID, device) | ||
c.Labels = []module.Label{ | ||
{Key: "device", Value: device}, | ||
} | ||
for _, d := range c.Dims { | ||
d.ID = fmt.Sprintf(d.ID, device) | ||
} | ||
} | ||
|
||
return charts | ||
} | ||
|
||
func (w *WireGuard) addNewDeviceCharts(device string) { | ||
charts := newDeviceCharts(device) | ||
|
||
if err := w.Charts().Add(*charts...); err != nil { | ||
w.Warning(err) | ||
} | ||
} | ||
|
||
func (w *WireGuard) removeDeviceCharts(device string) { | ||
prefix := fmt.Sprintf("device_%s", device) | ||
|
||
for _, c := range *w.Charts() { | ||
if strings.HasPrefix(c.ID, prefix) { | ||
c.MarkRemove() | ||
c.MarkNotCreated() | ||
} | ||
} | ||
} | ||
|
||
func newPeerCharts(id, device, pubKey string) *module.Charts { | ||
charts := peerChartsTmpl.Copy() | ||
|
||
for _, c := range *charts { | ||
c.ID = fmt.Sprintf(c.ID, id) | ||
c.Labels = []module.Label{ | ||
{Key: "device", Value: device}, | ||
{Key: "public_key", Value: pubKey}, | ||
} | ||
for _, d := range c.Dims { | ||
d.ID = fmt.Sprintf(d.ID, id) | ||
} | ||
} | ||
|
||
return charts | ||
} | ||
|
||
func (w *WireGuard) addNewPeerCharts(id, device, pubKey string) { | ||
charts := newPeerCharts(id, device, pubKey) | ||
|
||
if err := w.Charts().Add(*charts...); err != nil { | ||
w.Warning(err) | ||
} | ||
} | ||
|
||
func (w *WireGuard) removePeerCharts(id string) { | ||
prefix := fmt.Sprintf("peer_%s", id) | ||
|
||
for _, c := range *w.Charts() { | ||
if strings.HasPrefix(c.ID, prefix) { | ||
c.MarkRemove() | ||
c.MarkNotCreated() | ||
} | ||
} | ||
} |
Oops, something went wrong.