mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-16 03:49:52 +00:00
Add build constraint on Linux-only features
Split Reporter into Linux and non-Linux parts, and stubbed it out for non-Linux targets.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// +build linux
|
||||
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// +build linux
|
||||
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// +build linux
|
||||
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// +build linux
|
||||
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// +build linux
|
||||
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// +build linux
|
||||
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
51
probe/endpoint/reporter_linux.go
Normal file
51
probe/endpoint/reporter_linux.go
Normal file
@@ -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
|
||||
}
|
||||
21
probe/endpoint/reporter_other.go
Normal file
21
probe/endpoint/reporter_other.go
Normal file
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user