diff --git a/probe/endpoint/connection_tracker.go b/probe/endpoint/connection_tracker.go index 9b8495fa2..e65c4d3c5 100644 --- a/probe/endpoint/connection_tracker.go +++ b/probe/endpoint/connection_tracker.go @@ -1,3 +1,5 @@ +// +build linux + package endpoint import ( diff --git a/probe/endpoint/conntrack.go b/probe/endpoint/conntrack.go index cd4f69e5f..b20ffacda 100644 --- a/probe/endpoint/conntrack.go +++ b/probe/endpoint/conntrack.go @@ -1,3 +1,5 @@ +// +build linux + package endpoint import ( diff --git a/probe/endpoint/ebpf.go b/probe/endpoint/ebpf.go index 4dd173020..2a1e1aefe 100644 --- a/probe/endpoint/ebpf.go +++ b/probe/endpoint/ebpf.go @@ -1,3 +1,5 @@ +// +build linux + package endpoint import ( diff --git a/probe/endpoint/ebpf_test.go b/probe/endpoint/ebpf_test.go index 52baae8d3..cbca96799 100644 --- a/probe/endpoint/ebpf_test.go +++ b/probe/endpoint/ebpf_test.go @@ -1,3 +1,5 @@ +// +build linux + package endpoint import ( diff --git a/probe/endpoint/nat.go b/probe/endpoint/nat.go index d5eb71001..797a0d1a8 100644 --- a/probe/endpoint/nat.go +++ b/probe/endpoint/nat.go @@ -1,3 +1,5 @@ +// +build linux + package endpoint import ( diff --git a/probe/endpoint/nat_internal_test.go b/probe/endpoint/nat_internal_test.go index 27a1cc624..d4f3c4354 100644 --- a/probe/endpoint/nat_internal_test.go +++ b/probe/endpoint/nat_internal_test.go @@ -1,3 +1,5 @@ +// +build linux + package endpoint import ( diff --git a/probe/endpoint/reporter.go b/probe/endpoint/reporter.go index 2678a3174..709dc0f41 100644 --- a/probe/endpoint/reporter.go +++ b/probe/endpoint/reporter.go @@ -31,13 +31,6 @@ type ReporterConfig struct { DNSSnooper *DNSSnooper } -// Reporter generates Reports containing the Endpoint topology. -type Reporter struct { - conf ReporterConfig - connectionTracker connectionTracker - natMapper natMapper -} - // SpyDuration is an exported prometheus metric var SpyDuration = prometheus.NewSummaryVec( prometheus.SummaryOpts{ @@ -50,40 +43,5 @@ var SpyDuration = prometheus.NewSummaryVec( []string{}, ) -// NewReporter creates a new Reporter that invokes procspy.Connections to -// generate a report.Report that contains every discovered (spied) connection -// on the host machine, at the granularity of host and port. That information -// is stored in the Endpoint topology. It optionally enriches that topology -// with process (PID) information. -func NewReporter(conf ReporterConfig) *Reporter { - return &Reporter{ - conf: conf, - connectionTracker: newConnectionTracker(conf), - natMapper: makeNATMapper(newConntrackFlowWalker(conf.UseConntrack, conf.ProcRoot, conf.BufferSize, true /* natOnly */)), - } -} - // Name of this reporter, for metrics gathering func (Reporter) Name() string { return "Endpoint" } - -// Stop stop stop -func (r *Reporter) Stop() { - r.connectionTracker.Stop() - r.natMapper.stop() - if r.conf.Scanner != nil { - r.conf.Scanner.Stop() - } -} - -// Report implements Reporter. -func (r *Reporter) Report() (report.Report, error) { - defer func(begin time.Time) { - SpyDuration.WithLabelValues().Observe(time.Since(begin).Seconds()) - }(time.Now()) - - rpt := report.MakeReport() - - r.connectionTracker.ReportConnections(&rpt) - r.natMapper.applyNAT(rpt, r.conf.HostID) - return rpt, nil -} diff --git a/probe/endpoint/reporter_linux.go b/probe/endpoint/reporter_linux.go new file mode 100644 index 000000000..dd7444c2b --- /dev/null +++ b/probe/endpoint/reporter_linux.go @@ -0,0 +1,51 @@ +// +build linux + +package endpoint + +import ( + "time" + + "github.com/weaveworks/scope/report" +) + +// Reporter generates Reports containing the Endpoint topology. +type Reporter struct { + conf ReporterConfig + connectionTracker connectionTracker + natMapper natMapper +} + +// NewReporter creates a new Reporter that invokes procspy.Connections to +// generate a report.Report that contains every discovered (spied) connection +// on the host machine, at the granularity of host and port. That information +// is stored in the Endpoint topology. It optionally enriches that topology +// with process (PID) information. +func NewReporter(conf ReporterConfig) *Reporter { + return &Reporter{ + conf: conf, + connectionTracker: newConnectionTracker(conf), + natMapper: makeNATMapper(newConntrackFlowWalker(conf.UseConntrack, conf.ProcRoot, conf.BufferSize, true /* natOnly */)), + } +} + +// Stop stop stop +func (r *Reporter) Stop() { + r.connectionTracker.Stop() + r.natMapper.stop() + if r.conf.Scanner != nil { + r.conf.Scanner.Stop() + } +} + +// Report implements Reporter. +func (r *Reporter) Report() (report.Report, error) { + defer func(begin time.Time) { + SpyDuration.WithLabelValues().Observe(time.Since(begin).Seconds()) + }(time.Now()) + + rpt := report.MakeReport() + + r.connectionTracker.ReportConnections(&rpt) + r.natMapper.applyNAT(rpt, r.conf.HostID) + return rpt, nil +} diff --git a/probe/endpoint/reporter_other.go b/probe/endpoint/reporter_other.go new file mode 100644 index 000000000..bf77b5d64 --- /dev/null +++ b/probe/endpoint/reporter_other.go @@ -0,0 +1,21 @@ +// +build !linux + +package endpoint + +import "github.com/weaveworks/scope/report" + +// Reporter dummy +type Reporter struct{} + +// NewReporter makes a dummy +func NewReporter(conf ReporterConfig) *Reporter { + return &Reporter{} +} + +// Stop dummy +func (r *Reporter) Stop() {} + +// Report implements Reporter. +func (r *Reporter) Report() (report.Report, error) { + return report.MakeReport(), nil +}