From c607ee00d80ad04eab52a64305d758ed2d3d63d8 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Wed, 23 Sep 2015 14:38:41 +0200 Subject: [PATCH] probe/sniff: move to experimental Resolves #466 --- {probe => experimental}/sniff/sniffer.go | 43 ++++++++++++++++++- .../sniff/sniffer_internal_test.go | 0 {probe => experimental}/sniff/sniffer_test.go | 2 +- {probe => experimental}/sniff/source.go | 0 .../sniff/testclient/main.go | 0 probe/main.go | 39 ----------------- 6 files changed, 42 insertions(+), 42 deletions(-) rename {probe => experimental}/sniff/sniffer.go (90%) rename {probe => experimental}/sniff/sniffer_internal_test.go (100%) rename {probe => experimental}/sniff/sniffer_test.go (98%) rename {probe => experimental}/sniff/source.go (100%) rename {probe => experimental}/sniff/testclient/main.go (100%) diff --git a/probe/sniff/sniffer.go b/experimental/sniff/sniffer.go similarity index 90% rename from probe/sniff/sniffer.go rename to experimental/sniff/sniffer.go index 134911241..9d97908ad 100644 --- a/probe/sniff/sniffer.go +++ b/experimental/sniff/sniffer.go @@ -8,12 +8,51 @@ import ( "sync/atomic" "time" - "github.com/weaveworks/scope/report" - "github.com/google/gopacket" "github.com/google/gopacket/layers" + + "github.com/weaveworks/scope/report" ) +/* +It's important to adjust GOMAXPROCS when using sniffer: + +if *captureEnabled { + var sniffers int + for _, iface := range strings.Split(*captureInterfaces, ",") { + source, err := sniff.NewSource(iface) + if err != nil { + log.Printf("warning: %v", err) + continue + } + defer source.Close() + log.Printf("capturing packets on %s", iface) + reporters = append(reporters, sniff.New(hostID, localNets, source, *captureOn, *captureOff)) + sniffers++ + } + // Packet capture can block OS threads on Linux, so we need to provide + // sufficient overhead in GOMAXPROCS. + if have, want := runtime.GOMAXPROCS(-1), (sniffers + 1); have < want { + runtime.GOMAXPROCS(want) + } +} + +func interfaces() string { + ifaces, err := net.Interfaces() + if err != nil { + log.Print(err) + return "" + } + a := make([]string, 0, len(ifaces)) + for _, iface := range ifaces { + a = append(a, iface.Name) + } + return strings.Join(a, ",") +} + +Also, the capture on/off sampling methodology is probably not worth keeping. +*/ + // Sniffer is a packet-sniffing reporter. type Sniffer struct { hostID string diff --git a/probe/sniff/sniffer_internal_test.go b/experimental/sniff/sniffer_internal_test.go similarity index 100% rename from probe/sniff/sniffer_internal_test.go rename to experimental/sniff/sniffer_internal_test.go diff --git a/probe/sniff/sniffer_test.go b/experimental/sniff/sniffer_test.go similarity index 98% rename from probe/sniff/sniffer_test.go rename to experimental/sniff/sniffer_test.go index 21ab7aa14..0dcbe706d 100644 --- a/probe/sniff/sniffer_test.go +++ b/experimental/sniff/sniffer_test.go @@ -10,7 +10,7 @@ import ( "github.com/google/gopacket" - "github.com/weaveworks/scope/probe/sniff" + "github.com/weaveworks/scope/experimental/sniff" "github.com/weaveworks/scope/report" "github.com/weaveworks/scope/test" ) diff --git a/probe/sniff/source.go b/experimental/sniff/source.go similarity index 100% rename from probe/sniff/source.go rename to experimental/sniff/source.go diff --git a/probe/sniff/testclient/main.go b/experimental/sniff/testclient/main.go similarity index 100% rename from probe/sniff/testclient/main.go rename to experimental/sniff/testclient/main.go diff --git a/probe/main.go b/probe/main.go index eb4495ff9..a8dd86dda 100644 --- a/probe/main.go +++ b/probe/main.go @@ -9,7 +9,6 @@ import ( _ "net/http/pprof" "os" "os/signal" - "runtime" "strings" "syscall" "time" @@ -20,7 +19,6 @@ import ( "github.com/weaveworks/scope/probe/host" "github.com/weaveworks/scope/probe/overlay" "github.com/weaveworks/scope/probe/process" - "github.com/weaveworks/scope/probe/sniff" "github.com/weaveworks/scope/report" "github.com/weaveworks/scope/xfer" ) @@ -41,10 +39,6 @@ func main() { dockerBridge = flag.String("docker.bridge", "docker0", "the docker bridge name") weaveRouterAddr = flag.String("weave.router.addr", "", "IP address or FQDN of the Weave router") procRoot = flag.String("proc.root", "/proc", "location of the proc filesystem") - captureEnabled = flag.Bool("capture", false, "perform sampled packet capture") - captureInterfaces = flag.String("capture.interfaces", interfaces(), "packet capture on these interfaces") - captureOn = flag.Duration("capture.on", 1*time.Second, "packet capture duty cycle 'on'") - captureOff = flag.Duration("capture.off", 5*time.Second, "packet capture duty cycle 'off'") printVersion = flag.Bool("version", false, "print version number and exit") useConntrack = flag.Bool("conntrack", true, "also use conntrack to track connections") ) @@ -148,26 +142,6 @@ func main() { reporters = append(reporters, weave) } - if *captureEnabled { - var sniffers int - for _, iface := range strings.Split(*captureInterfaces, ",") { - source, err := sniff.NewSource(iface) - if err != nil { - log.Printf("warning: %v", err) - continue - } - defer source.Close() - log.Printf("capturing packets on %s", iface) - reporters = append(reporters, sniff.New(hostID, localNets, source, *captureOn, *captureOff)) - sniffers++ - } - // Packet capture can block OS threads on Linux, so we need to provide - // sufficient overhead in GOMAXPROCS. - if have, want := runtime.GOMAXPROCS(-1), (sniffers + 1); have < want { - runtime.GOMAXPROCS(want) - } - } - quit := make(chan struct{}) defer close(quit) go func() { @@ -237,16 +211,3 @@ func interrupt() chan os.Signal { signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) return c } - -func interfaces() string { - ifaces, err := net.Interfaces() - if err != nil { - log.Print(err) - return "" - } - a := make([]string, 0, len(ifaces)) - for _, iface := range ifaces { - a = append(a, iface.Name) - } - return strings.Join(a, ",") -}