From aaaf6db09315ec333bc4f6866c5e481384f408c1 Mon Sep 17 00:00:00 2001 From: Sascha Steinbiss Date: Fri, 17 Jul 2026 18:19:49 +0200 Subject: [PATCH 1/4] add Go module support --- go.mod | 14 ++++++++++++++ go.sum | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 go.mod create mode 100644 go.sum diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..9dccf29 --- /dev/null +++ b/go.mod @@ -0,0 +1,14 @@ +module github.com/DCSO/ethflux + +go 1.26.3 + +require ( + github.com/DCSO/fluxline v0.0.0-20200907065040-78686e5e68f6 + github.com/safchain/ethtool v0.7.0 + github.com/sirupsen/logrus v1.9.4 +) + +require ( + github.com/Showmax/go-fqdn v1.0.0 // indirect + golang.org/x/sys v0.38.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..a983346 --- /dev/null +++ b/go.sum @@ -0,0 +1,18 @@ +github.com/DCSO/fluxline v0.0.0-20200907065040-78686e5e68f6 h1:ILpYBsvnQwnM7PvDKoLjLx47tE0jPsR/oX3CvhuhJG4= +github.com/DCSO/fluxline v0.0.0-20200907065040-78686e5e68f6/go.mod h1:PvQC78r0wMuOsJ8Sl9isIEYR+00WKI/gliLjVYfDVjQ= +github.com/Showmax/go-fqdn v1.0.0 h1:0rG5IbmVliNT5O19Mfuvna9LL7zlHyRfsSvBPZmF9tM= +github.com/Showmax/go-fqdn v1.0.0/go.mod h1:SfrFBzmDCtCGrnHhoDjuvFnKsWjEQX/Q9ARZvOrJAko= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/safchain/ethtool v0.7.0 h1:rlJzfDetsVvT61uz8x1YIcFn12akMfuPulHtZjtb7Is= +github.com/safchain/ethtool v0.7.0/go.mod h1:MenQKEjXdfkjD3mp2QdCk8B/hwvkrlOTm/FD4gTpFxQ= +github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w= +github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc= +golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 5b7033b60bea94307e9e3b409f91b9da5a54b4ba Mon Sep 17 00:00:00 2001 From: Sascha Steinbiss Date: Fri, 17 Jul 2026 18:20:01 +0200 Subject: [PATCH 2/4] add -sum-fields --- ethflux.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/ethflux.go b/ethflux.go index af63e50..390122f 100644 --- a/ethflux.go +++ b/ethflux.go @@ -10,12 +10,47 @@ import ( "net" "os" "regexp" + "strings" "github.com/DCSO/fluxline" - log "github.com/Sirupsen/logrus" "github.com/safchain/ethtool" + log "github.com/sirupsen/logrus" ) +// sumField describes a derived field that is computed as the sum of all +// existing fields whose name matches Pattern. +type sumField struct { + Name string + Pattern *regexp.Regexp +} + +// sumFieldsFlag allows the -sum-field flag to be specified multiple times, +// each in the form name=regex. +type sumFieldsFlag []sumField + +func (s *sumFieldsFlag) String() string { + parts := make([]string, len(*s)) + for i, f := range *s { + parts[i] = fmt.Sprintf("%s=%s", f.Name, f.Pattern.String()) + } + return strings.Join(parts, ",") +} + +func (s *sumFieldsFlag) Set(value string) error { + idx := strings.Index(value, "=") + if idx < 0 { + return fmt.Errorf("invalid -sum-field value %q, expected format name=regex", value) + } + name := value[:idx] + pattern := value[idx+1:] + re, err := regexp.Compile(pattern) + if err != nil { + return fmt.Errorf("invalid regex in -sum-field %q: %w", value, err) + } + *s = append(*s, sumField{Name: name, Pattern: re}) + return nil +} + func main() { msmt := flag.String("measurement", "ethtool", @@ -23,6 +58,9 @@ func main() { help := flag.Bool("help", false, "show help") quiet := flag.Bool("quiet", false, "do not show warnings") useHostname := flag.Bool("hostname", false, "use os.Hostname() rather than FQDN") + var sumFields sumFieldsFlag + flag.Var(&sumFields, "sum-field", + "add a derived field as name=regex, summing all fields matching regex (can be repeated)") flag.Parse() argsWithoutProg := flag.Args() @@ -33,7 +71,7 @@ func main() { } if *help { - fmt.Fprintln(os.Stderr, "Usage: ethflux [-help] [-quiet] [-hostname] [-measurement=string] ") + fmt.Fprintln(os.Stderr, "Usage: ethflux [-help] [-quiet] [-hostname] [-measurement=string] [-sum-field=name=regex ...] ") flag.PrintDefaults() os.Exit(1) } @@ -77,6 +115,16 @@ func main() { log.Fatal(err) } + for _, sf := range sumFields { + var sum uint64 + for k, v := range stats { + if sf.Pattern.MatchString(k) { + sum += v + } + } + stats[sf.Name] = sum + } + stringStats := make(map[string]string) for k, v := range stats { stringStats[k] = fmt.Sprintf("%d", v) From fd0b32748d7d9732dfda52c0205921cd4863915f Mon Sep 17 00:00:00 2001 From: Sascha Steinbiss Date: Fri, 17 Jul 2026 18:22:01 +0200 Subject: [PATCH 3/4] update README.md --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8d465f4..2d1042e 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ ## Getting the code ``` -go get github.com/DCSO/ethflux.git +cd ethflux +go get ./... ``` ## Building @@ -20,13 +21,17 @@ will produce an `ethflux` binary. ## Usage ``` -Usage: ethflux [-help] [-quiet] [-measurement=string] +Usage: ethflux [-help] [-quiet] [-hostname] [-measurement=string] [-sum-field=name=regex ...] -help show help + -hostname + use os.Hostname() rather than FQDN -measurement string name of measurement to use in line (default "ethtool") -quiet do not show warnings + -sum-field value + add a derived field as name=regex, summing all fields matching regex (can be repeated) ``` The interface parameter supports regular expressions, e.g. `wl.*` would match `wlp4s0` etc. From f488c4e27892252d812a0e4b73663109b7b44efd Mon Sep 17 00:00:00 2001 From: Sascha Steinbiss Date: Fri, 17 Jul 2026 18:22:12 +0200 Subject: [PATCH 4/4] add .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0297656 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +ethflux