From 5b604283c2f1a65b85934149ccfb9ec325015baf Mon Sep 17 00:00:00 2001 From: Jay Camp Date: Tue, 21 Jan 2020 15:52:51 -0500 Subject: [PATCH] Improve performance of host observer This skips the uid lookup since we don't use it. See upstream PRs for some more background: https://github.com/shirou/gopsutil/issues/784 https://github.com/shirou/gopsutil/pull/783 This requires upgrading gopsutil which changed some structs which in turn requires upgrading telegraf. Apparently the `Stolen` field was never set (https://github.com/shirou/gopsutil/pull/677) Even with this change there are still some performance issues in the host observer on machines with a large number of connections. Something like this change would be required to deal with the remaining issues: https://github.com/shirou/gopsutil/issues/695 --- go.mod | 6 +++--- go.sum | 6 ++++++ pkg/monitors/cpu/cpu.go | 3 +-- pkg/monitors/telegraf/common/accumulator/accumulator.go | 2 +- .../telegraf/common/accumulator/accumulator_test.go | 2 +- pkg/observers/host/host.go | 2 +- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index f5cd74e09f..938eff19aa 100644 --- a/go.mod +++ b/go.mod @@ -82,7 +82,7 @@ require ( github.com/influxdata/influxdb v1.7.4 // indirect github.com/influxdata/platform v0.0.0-20190117200541-d500d3cf5589 // indirect github.com/influxdata/tail v1.0.0 // indirect - github.com/influxdata/telegraf v0.10.2-0.20190319005412-5e88824c153e + github.com/influxdata/telegraf v0.10.2-0.20200121190823-6dad859d74c2 github.com/influxdata/toml v0.0.0-20180607005434-2a2e3012f7cf // indirect github.com/influxdata/wlog v0.0.0-20160411224016-7c63b0a71ef8 // indirect github.com/jaegertracing/jaeger v1.15.1 @@ -122,7 +122,7 @@ require ( github.com/prometheus/common v0.2.1-0.20190321124555-1ab4d74fc899 github.com/prometheus/procfs v0.0.9-0.20191209220459-fa4d6ce8c078 github.com/samuel/go-zookeeper v0.0.0-20190810000440-0ceca61e4d75 - github.com/shirou/gopsutil v2.18.12+incompatible + github.com/shirou/gopsutil v2.19.12+incompatible github.com/signalfx/com_signalfx_metrics_protobuf v0.0.0-20190222193949-1fb69526e884 github.com/signalfx/defaults v1.2.2-0.20180531161417-70562fe60657 github.com/signalfx/gateway v1.2.19-0.20191125135538-2c417b7ae0bd @@ -130,7 +130,7 @@ require ( github.com/signalfx/signalfx-go v1.6.9-0.20191121015807-da8b1dfaab43 github.com/sirupsen/logrus v1.4.0 github.com/smartystreets/goconvey v1.6.4 - github.com/soniah/gosnmp v0.0.0-20190220004421-68e8beac0db9 // indirect + github.com/soniah/gosnmp v1.22.0 // indirect github.com/streadway/amqp v0.0.0-20190312223743-14f78b41ce6d // indirect github.com/stretchr/testify v1.4.0 github.com/tidwall/gjson v1.2.1 // indirect diff --git a/go.sum b/go.sum index 7e3770f1c7..c5533f7736 100644 --- a/go.sum +++ b/go.sum @@ -493,6 +493,8 @@ github.com/influxdata/tail v1.0.0/go.mod h1:xTFF2SILpIYc5N+Srb0d5qpx7d+f733nBrba github.com/influxdata/tdigest v0.0.0-20181121200506-bf2b5ad3c0a9/go.mod h1:Js0mqiSBE6Ffsg94weZZ2c+v/ciT8QRHFOap7EKDrR0= github.com/influxdata/telegraf v0.10.2-0.20190319005412-5e88824c153e h1:tfGPLDKE2X1PaU0TQn7H0ZkoNrcVW2a33CnSd8uSTi4= github.com/influxdata/telegraf v0.10.2-0.20190319005412-5e88824c153e/go.mod h1:HIOhVICa+3kYiBmzfDt9LEnDA++FNzRzf9eP0o365us= +github.com/influxdata/telegraf v0.10.2-0.20200121190823-6dad859d74c2 h1:7+1SwH+Qw6NRc5SWThS5bkVjeG1T4yDBVpDAECWQmQ0= +github.com/influxdata/telegraf v0.10.2-0.20200121190823-6dad859d74c2/go.mod h1:HIOhVICa+3kYiBmzfDt9LEnDA++FNzRzf9eP0o365us= github.com/influxdata/toml v0.0.0-20180607005434-2a2e3012f7cf h1:SDlFXYATjEbWThjvSTGdLmHyPozB8QsUFQs/LQ/bOcE= github.com/influxdata/toml v0.0.0-20180607005434-2a2e3012f7cf/go.mod h1:zApaNFpP/bTpQItGZNNUMISDMDAnTXu9UqJ4yT3ocz8= github.com/influxdata/usage-client v0.0.0-20160829180054-6d3895376368/go.mod h1:Wbbw6tYNvwa5dlB6304Sd+82Z3f7PmVZHVKU637d4po= @@ -757,6 +759,8 @@ github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAm github.com/shirou/gopsutil v2.18.10+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shirou/gopsutil v2.18.12+incompatible h1:1eaJvGomDnH74/5cF4CTmTbLHAriGFsTZppLXDX93OM= github.com/shirou/gopsutil v2.18.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= +github.com/shirou/gopsutil v2.19.12+incompatible h1:WRstheAymn1WOPesh+24+bZKFkqrdCR8JOc77v4xV3Q= +github.com/shirou/gopsutil v2.19.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 h1:udFKJ0aHUL60LboW/A+DfgoHVedieIzIXE8uylPue0U= github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc= github.com/signalfx/com_signalfx_metrics_protobuf v0.0.0-20190222193949-1fb69526e884 h1:KgLGEw137KEUtQnWBGzneCetphBj4+kKHRnhpAkXJC0= @@ -814,6 +818,8 @@ github.com/soheilhy/cmux v0.1.5-0.20181025144106-8a8ea3c53959 h1:AulKUH62UkjPFbb github.com/soheilhy/cmux v0.1.5-0.20181025144106-8a8ea3c53959/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/soniah/gosnmp v0.0.0-20190220004421-68e8beac0db9 h1:O4jq14rgUwG9Ssn0wZiRPl8Ya6q3a1h3xJzTAsBaRgo= github.com/soniah/gosnmp v0.0.0-20190220004421-68e8beac0db9/go.mod h1:DuEpAS0az51+DyVBQwITDsoq4++e3LTNckp2GoasF2I= +github.com/soniah/gosnmp v1.22.0 h1:jVJi8+OGvR+JHIaZKMmnyNP0akJd2vEgNatybwhZvxg= +github.com/soniah/gosnmp v1.22.0/go.mod h1:DuEpAS0az51+DyVBQwITDsoq4++e3LTNckp2GoasF2I= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= diff --git a/pkg/monitors/cpu/cpu.go b/pkg/monitors/cpu/cpu.go index a304a34f5b..799acadced 100644 --- a/pkg/monitors/cpu/cpu.go +++ b/pkg/monitors/cpu/cpu.go @@ -240,8 +240,7 @@ func cpuTimeStatTototalUsed(t *cpu.TimesStat) *totalUsed { t.Softirq + t.Steal + t.Guest + - t.GuestNice + - t.Stolen + t.GuestNice return &totalUsed{ Total: total, diff --git a/pkg/monitors/telegraf/common/accumulator/accumulator.go b/pkg/monitors/telegraf/common/accumulator/accumulator.go index 35691be0a6..ed31919964 100644 --- a/pkg/monitors/telegraf/common/accumulator/accumulator.go +++ b/pkg/monitors/telegraf/common/accumulator/accumulator.go @@ -67,7 +67,7 @@ func (ac *Accumulator) AddHistogram(measurement string, fields map[string]interf } // SetPrecision - SignalFx does not implement this -func (ac *Accumulator) SetPrecision(precision, interval time.Duration) { +func (ac *Accumulator) SetPrecision(precision time.Duration) { } // AddError - log an error returned by the plugin diff --git a/pkg/monitors/telegraf/common/accumulator/accumulator_test.go b/pkg/monitors/telegraf/common/accumulator/accumulator_test.go index 809b94bf64..461058ba7d 100644 --- a/pkg/monitors/telegraf/common/accumulator/accumulator_test.go +++ b/pkg/monitors/telegraf/common/accumulator/accumulator_test.go @@ -125,7 +125,7 @@ func TestAccumulator(t *testing.T) { } t.Run("SetPrecision()", func(t *testing.T) { ac.emit = &testEmitter{} - ac.SetPrecision(time.Second*1, time.Second*1) + ac.SetPrecision(time.Second * 1) }) t.Run("AddError()", func(t *testing.T) { ac.emit = &testEmitter{} diff --git a/pkg/observers/host/host.go b/pkg/observers/host/host.go index 5b8477305d..31e9246235 100644 --- a/pkg/observers/host/host.go +++ b/pkg/observers/host/host.go @@ -89,7 +89,7 @@ func portTypeToProtocol(t uint32) services.PortType { } func (o *Observer) discover() []services.Endpoint { - conns, err := net.Connections("all") + conns, err := net.ConnectionsWithoutUids("all") if err != nil { o.logger.WithError(err).Error("Could not get local network listeners") return nil