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 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
723 additions
and
3 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
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,105 @@ | ||
# netdata go.d.plugin configuration for ping | ||
# | ||
# 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 | ||
# | ||
# | ||
# [ List of JOB specific parameters ]: | ||
# - targets | ||
# A list of target to send ping packets to. | ||
# Syntax: | ||
# targets: | ||
# - 192.0.2.0 | ||
# - 192.0.2.1 | ||
# - example.com | ||
# | ||
# - privileged | ||
# Sets the type of ping packets. | ||
# "no" means send an "unprivileged" UDP ping. "yes" means send a "privileged" raw ICMP ping. | ||
# Syntax: | ||
# privileged: yes/no | ||
# | ||
# - packets | ||
# Number of ping packets to send. | ||
# Syntax: | ||
# packets: 3 | ||
# | ||
# - interval | ||
# Time to wait between sending ping packets. | ||
# Syntax: | ||
# interval: 100ms | ||
# | ||
# | ||
# [ JOB defaults ]: | ||
# privileged: yes | ||
# packets: 5 | ||
# interval: 200ms | ||
# | ||
# | ||
# [ JOB mandatory parameters ]: | ||
# No parameters | ||
# | ||
# ------------------------------------------------MODULE-CONFIGURATION-------------------------------------------------- | ||
|
||
# update_every: 5 | ||
# autodetection_retry: 0 | ||
# priority: 70000 | ||
|
||
## Uncomment the following lines to create a data collection config: | ||
|
||
# jobs: | ||
# - name: example | ||
# targets: | ||
# - 192.0.2.0 | ||
# - 192.0.2.1 |
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,89 @@ | ||
<!-- | ||
title: "Pi-hole monitoring with Netdata" | ||
description: "Monitor round-trip time and packet loss to network hosts with zero configuration, per-second metric granularity, and interactive visualizations." | ||
custom_edit_url: https://github.com/netdata/go.d.plugin/edit/master/modules/ping/README.md | ||
sidebar_label: "Ping" | ||
--> | ||
|
||
# Ping monitoring with Netdata | ||
|
||
This module measures round-tripe time and packet loss by sending ping messages to network hosts. | ||
|
||
## Requirements | ||
|
||
There are two operational modes: | ||
|
||
- privileged (send UDP ping, default). Requires | ||
CAP_NET_RAW [capability](https://man7.org/linux/man-pages/man7/capabilities.7.html) or root privileges: | ||
> **Note**: set automatically during Netdata installation. | ||
```bash | ||
sudo setcap CAP_NET_RAW=eip <INSTALL_PREFIX>/usr/libexec/netdata/plugins.d/go.d.plugin | ||
``` | ||
|
||
- unprivileged (send raw ICMP ping, Linux only). | ||
Requires configuring [ping_group_range](https://www.man7.org/linux/man-pages/man7/icmp.7.html): | ||
|
||
```bash | ||
sudo sysctl -w net.ipv4.ping_group_range="0 2147483647" | ||
``` | ||
To persist the change add `net.ipv4.ping_group_range="0 2147483647"` to `/etc/sysctl.conf` and | ||
execute `sudo sysctl -p`. | ||
|
||
The mode can be changed in the module [configuration file](#Configuration). | ||
|
||
## Metrics | ||
|
||
All metrics have "ping." prefix. | ||
|
||
| Metric | Scope | Dimensions | Units | | ||
|--------------------|:------:|:--------------:|:----------:| | ||
| target_rtt | target | min, max, avg | seconds | | ||
| target_packet_loss | target | loss | percentage | | ||
| target_packets | target | received, sent | packets | | ||
|
||
## Configuration | ||
|
||
Edit the `go.d/ping.conf` configuration file using `edit-config` from the | ||
Netdata [config directory](https://learn.netdata.cloud/docs/configure/nodes), which is typically at `/etc/netdata`. | ||
|
||
```bash | ||
cd /etc/netdata # Replace this path with your Netdata config directory | ||
sudo ./edit-config go.d/ping.conf | ||
``` | ||
|
||
Here is an example configuration: | ||
|
||
```yaml | ||
jobs: | ||
- name: example | ||
targets: | ||
- 192.0.2.0 | ||
- 192.0.2.1 | ||
- example.com | ||
packets: 5 # number of ping packets to send. | ||
interval: 200ms # time to wait between sending ping packets. | ||
``` | ||
For all available options please see | ||
module [configuration file](https://github.com/netdata/go.d.plugin/blob/master/config/go.d/ping.conf). | ||
## Troubleshooting | ||
To troubleshoot issues with the `ping` 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 ping | ||
``` |
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,86 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
package ping | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/netdata/go.d.plugin/agent/module" | ||
) | ||
|
||
const ( | ||
prioTargetRTTLatency = module.Priority + iota | ||
prioTargetPingPacketLoss | ||
prioTargetPingPackets | ||
) | ||
|
||
var targetChartsTmpl = module.Charts{ | ||
targetRTTChartTmpl.Copy(), | ||
targetPacketLossChartTmpl.Copy(), | ||
targetPacketsChartTmpl.Copy(), | ||
} | ||
|
||
var targetRTTChartTmpl = module.Chart{ | ||
ID: "ping_target_%s_rtt", | ||
Title: "Ping round-trip time", | ||
Units: "seconds", | ||
Fam: "latency", | ||
Ctx: "ping.target_rtt", | ||
Priority: prioTargetRTTLatency, | ||
Type: module.Area, | ||
Dims: module.Dims{ | ||
{ID: "target_%s_min_rtt", Name: "min", Div: 1e6}, | ||
{ID: "target_%s_max_rtt", Name: "max", Div: 1e6}, | ||
{ID: "target_%s_avg_rtt", Name: "avg", Div: 1e6}, | ||
}, | ||
} | ||
|
||
var targetPacketLossChartTmpl = module.Chart{ | ||
ID: "target_host_%s_packet_loss", | ||
Title: "Ping packet loss", | ||
Units: "percentage", | ||
Fam: "packet loss", | ||
Ctx: "ping.target_packet_loss", | ||
Priority: prioTargetPingPacketLoss, | ||
Dims: module.Dims{ | ||
{ID: "target_%s_packet_loss", Name: "loss", Div: 1000}, | ||
}, | ||
} | ||
|
||
var targetPacketsChartTmpl = module.Chart{ | ||
ID: "target_host_%s_packets", | ||
Title: "Ping packets transferred", | ||
Units: "packets", | ||
Fam: "packets", | ||
Ctx: "ping.target_packets", | ||
Priority: prioTargetPingPackets, | ||
Dims: module.Dims{ | ||
{ID: "target_%s_packets_recv", Name: "received"}, | ||
{ID: "target_%s_packets_sent", Name: "sent"}, | ||
}, | ||
} | ||
|
||
func newTargetCharts(target string) *module.Charts { | ||
charts := targetChartsTmpl.Copy() | ||
|
||
for _, chart := range *charts { | ||
chart.ID = fmt.Sprintf(chart.ID, strings.ReplaceAll(target, ".", "_")) | ||
chart.Labels = []module.Label{ | ||
{Key: "target", Value: target}, | ||
} | ||
for _, dim := range chart.Dims { | ||
dim.ID = fmt.Sprintf(dim.ID, target) | ||
} | ||
} | ||
|
||
return charts | ||
} | ||
|
||
func (p *Ping) addTargetCharts(target string) { | ||
charts := newTargetCharts(target) | ||
|
||
if err := p.Charts().Add(*charts...); err != nil { | ||
p.Warning(err) | ||
} | ||
} |
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,49 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
package ping | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
) | ||
|
||
func (p *Ping) collect() (map[string]int64, error) { | ||
mu := &sync.Mutex{} | ||
mx := make(map[string]int64) | ||
var wg sync.WaitGroup | ||
|
||
for _, v := range p.Targets { | ||
wg.Add(1) | ||
go func(v string) { defer wg.Done(); p.pingTarget(v, mx, mu) }(v) | ||
} | ||
wg.Wait() | ||
|
||
return mx, nil | ||
} | ||
|
||
func (p *Ping) pingTarget(target string, mx map[string]int64, mu *sync.Mutex) { | ||
stats, err := p.prober.ping(target) | ||
if err != nil { | ||
p.Error(err) | ||
return | ||
} | ||
|
||
mu.Lock() | ||
defer mu.Unlock() | ||
|
||
if !p.targets[target] { | ||
p.targets[target] = true | ||
p.addTargetCharts(target) | ||
} | ||
|
||
px := fmt.Sprintf("target_%s_", target) | ||
if stats.PacketsRecv != 0 { | ||
mx[px+"min_rtt"] = stats.MinRtt.Microseconds() | ||
mx[px+"max_rtt"] = stats.MaxRtt.Microseconds() | ||
mx[px+"avg_rtt"] = stats.AvgRtt.Microseconds() | ||
mx[px+"std_dev_rtt"] = stats.StdDevRtt.Microseconds() | ||
} | ||
mx[px+"packets_recv"] = int64(stats.PacketsRecv) | ||
mx[px+"packets_sent"] = int64(stats.PacketsSent) | ||
mx[px+"packet_loss"] = int64(stats.PacketLoss * 1000) | ||
} |
Oops, something went wrong.