Skip to content

Commit

Permalink
Merge pull request #61 from SuperQ/superq/size_config
Browse files Browse the repository at this point in the history
Add option to adjust packet size
  • Loading branch information
SuperQ authored Jan 11, 2022
2 parents 0c84585 + 1db5c9f commit 7c0cfd8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>] [<hosts>...]
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:
[<hosts>] List of hosts to ping
Expand All @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var (
Interval: time.Second,
Network: "ip",
Protocol: "icmp",
Size: 56,
}
)

Expand Down Expand Up @@ -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"`
}
Expand Down
15 changes: 14 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
)

Expand All @@ -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)
Expand Down Expand Up @@ -149,6 +155,7 @@ func main() {
pinger.Timeout = time.Duration(math.MaxInt64)
pinger.RecordRtts = false
pinger.SetPrivileged(*privileged)
pinger.Size = *sizeBytes

pingers[i] = pinger
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions smokeping_prober.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ targets:
- hosts:
- localhost
interval: '0.5s'
size: 56

0 comments on commit 7c0cfd8

Please sign in to comment.