From 1db5c9f9f96b97ba94d279f7b5cfd0932eb31c87 Mon Sep 17 00:00:00 2001 From: SuperQ Date: Sun, 2 Jan 2022 21:07:38 +0100 Subject: [PATCH] Add option to adjust packet size * Add flag to allow packet data size. * Add config option for size per group. * Default to 56 bytes (64 byte packet). * Update docs. Fixes: https://github.com/SuperQ/smokeping_prober/issues/2 Signed-off-by: SuperQ --- README.md | 27 +++++++++++++-------------- config/config.go | 2 ++ main.go | 15 ++++++++++++++- smokeping_prober.yml | 1 + 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index f6de092..82f06cc 100644 --- a/README.md +++ b/README.md @@ -15,23 +15,21 @@ This prober sends a series of ICMP (or UDP) pings to a target and records the re usage: smokeping_prober [] [...] Flags: - -h, --help Show context-sensitive help (also try --help-long and --help-man). - --config.file="smokeping_prober.yml" - Optional smokeping_prober configuration file. + -h, --help Show context-sensitive help (also try --help-long and --help-man). + --config.file=CONFIG.FILE Optional smokeping_prober configuration yaml file. --web.listen-address=":9374" - Address on which to expose metrics and web interface. + Address on which to expose metrics and web interface. --web.telemetry-path="/metrics" - Path under which to expose metrics. + Path under which to expose metrics. --buckets="5e-05,0.0001,0.0002,0.0004,0.0008,0.0016,0.0032,0.0064,0.0128,0.0256,0.0512,0.1024,0.2048,0.4096,0.8192,1.6384,3.2768,6.5536,13.1072,26.2144" - A comma delimited list of buckets to use - -i, --ping.interval=1s Ping interval duration - --privileged Run in privileged ICMP mode - --log.level="info" Only log messages with the given severity or above. Valid levels: [debug, info, warn, - error, fatal] - --log.format="logger:stderr" - Set the log target and format. Example: "logger:syslog?appname=bob&local=7" or - "logger:stdout?json=true" - --version Show application version. + A comma delimited list of buckets to use + -i, --ping.interval=1s Ping interval duration + --privileged Run in privileged ICMP mode + -s, --ping.size=56 Ping packet size in bytes + --log.level=info Only log messages with the given severity or above. One of: [debug, info, warn, + error] + --log.format=logfmt Output format of log messages. One of: [logfmt, json] + --version Show application version. Args: [] List of hosts to ping @@ -52,6 +50,7 @@ targets: interval: 1s # Duration, Default 1s. network: ip # One of ip, ip4, ip6. Default: ip (automatic IPv4/IPv6) protocol: icmp # One of icmp, udp. Default: icmp (Requires privileged operation) + size: 56 # Packet data size in bytes. Default 56 (Range: 24 - 65535) ``` In each host group the `interval`, `network`, and `protocol` are optional. diff --git a/config/config.go b/config/config.go index 4ee33b1..3487487 100644 --- a/config/config.go +++ b/config/config.go @@ -46,6 +46,7 @@ var ( Interval: time.Second, Network: "ip", Protocol: "icmp", + Size: 56, } ) @@ -92,6 +93,7 @@ type TargetGroup struct { Interval time.Duration `yaml:"interval,omitempty"` Network string `yaml:"network,omitempty"` Protocol string `yaml:"protocol,omitempty"` + Size int `yaml:"size,omitempty"` // TODO: Needs work to fix MetricFamily consistency. // Labels map[string]string `yaml:"labels,omitempty"` } diff --git a/main.go b/main.go index c0f2d0d..be01a64 100644 --- a/main.go +++ b/main.go @@ -101,6 +101,7 @@ func main() { buckets = kingpin.Flag("buckets", "A comma delimited list of buckets to use").Default(defaultBuckets).String() interval = kingpin.Flag("ping.interval", "Ping interval duration").Short('i').Default("1s").Duration() privileged = kingpin.Flag("privileged", "Run in privileged ICMP mode").Default("true").Bool() + sizeBytes = kingpin.Flag("ping.size", "Ping packet size in bytes").Short('s').Default("56").Int() hosts = HostList(kingpin.Arg("hosts", "List of hosts to ping")) ) @@ -114,6 +115,11 @@ func main() { level.Info(logger).Log("msg", "Starting smokeping_prober", "version", version.Info()) level.Info(logger).Log("msg", "Build context", "build_context", version.BuildContext()) + if *sizeBytes < 24 || *sizeBytes > 65535 { + level.Error(logger).Log("msg", "Invalid packet size. (24-65535)", "bytes", *sizeBytes) + os.Exit(1) + } + if err := sc.ReloadConfig(*configFile); err != nil { if errors.Is(err, os.ErrNotExist) { level.Info(logger).Log("msg", "ignoring missing config file", "filename", *configFile) @@ -149,6 +155,7 @@ func main() { pinger.Timeout = time.Duration(math.MaxInt64) pinger.RecordRtts = false pinger.SetPrivileged(*privileged) + pinger.Size = *sizeBytes pingers[i] = pinger } @@ -160,10 +167,16 @@ func main() { if targetGroup.Interval > maxInterval { maxInterval = targetGroup.Interval } + packetSize := targetGroup.Size + if packetSize < 24 || packetSize > 65535 { + level.Error(logger).Log("msg", "Invalid packet size. (24-65535)", "bytes", packetSize) + return + } for _, host = range targetGroup.Hosts { pinger = ping.New(host) pinger.Interval = targetGroup.Interval pinger.SetNetwork(targetGroup.Network) + pinger.Size = packetSize if targetGroup.Protocol == "icmp" { pinger.SetPrivileged(true) } @@ -186,7 +199,7 @@ func main() { level.Info(logger).Log("msg", fmt.Sprintf("Waiting %s between starting pingers", splay)) g := new(errgroup.Group) for _, pinger := range pingers { - level.Info(logger).Log("msg", "Starting prober", "address", pinger.Addr(), "interval", pinger.Interval) + level.Info(logger).Log("msg", "Starting prober", "address", pinger.Addr(), "interval", pinger.Interval, "size_bytes", pinger.Size) g.Go(pinger.Run) time.Sleep(splay) } diff --git a/smokeping_prober.yml b/smokeping_prober.yml index b40594d..28f1481 100644 --- a/smokeping_prober.yml +++ b/smokeping_prober.yml @@ -3,3 +3,4 @@ targets: - hosts: - localhost interval: '0.5s' + size: 56