diff --git a/go.mod b/go.mod index bee5b220d725f..b372dabd1183b 100644 --- a/go.mod +++ b/go.mod @@ -171,7 +171,7 @@ require ( github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 github.com/sensu/sensu-go/api/core/v2 v2.16.0 github.com/shirou/gopsutil/v3 v3.24.4 - github.com/showwin/speedtest-go v1.7.5 + github.com/showwin/speedtest-go v1.7.6 github.com/signalfx/golib/v3 v3.3.53 github.com/sirupsen/logrus v1.9.3 github.com/sleepinggenius2/gosmi v0.4.4 diff --git a/go.sum b/go.sum index 4f306c09ac5cd..da67c5a95f4bc 100644 --- a/go.sum +++ b/go.sum @@ -2127,8 +2127,8 @@ github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9Nz github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= -github.com/showwin/speedtest-go v1.7.5 h1:FQ3EdM2vnfw5BRCRzGCYe8aWu70rr21Az5ZFHiW9CdE= -github.com/showwin/speedtest-go v1.7.5/go.mod h1:uLgdWCNarXxlYsL2E5TOZpCIwpgSWnEANZp7gfHXHu0= +github.com/showwin/speedtest-go v1.7.6 h1:wBbj4aJR+kq+DP44ja3hWEc50FCiSk0U0YQ9xQLORd0= +github.com/showwin/speedtest-go v1.7.6/go.mod h1:uLgdWCNarXxlYsL2E5TOZpCIwpgSWnEANZp7gfHXHu0= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/signalfx/com_signalfx_metrics_protobuf v0.0.3 h1:32k2QLgsKhcEs55q4REPKyIadvid5FPy2+VMgvbmKJ0= github.com/signalfx/com_signalfx_metrics_protobuf v0.0.3/go.mod h1:gJrXWi7wSGXfiC7+VheQaz+ypdCt5SmZNL+BRxUe7y4= diff --git a/plugins/inputs/internet_speed/internet_speed.go b/plugins/inputs/internet_speed/internet_speed.go index ff3150db8c37d..cf434994017f8 100644 --- a/plugins/inputs/internet_speed/internet_speed.go +++ b/plugins/inputs/internet_speed/internet_speed.go @@ -89,7 +89,7 @@ func (is *InternetSpeed) Gather(acc telegraf.Accumulator) error { SamplingDuration: time.Second * 15, }) - pLoss := -1.0 + var pLoss *transport.PLoss if is.TestMode == testModeMulti { err = is.server.MultiDownloadTestContext(context.Background(), is.servers) @@ -117,22 +117,17 @@ func (is *InternetSpeed) Gather(acc telegraf.Accumulator) error { } // Not all servers are applicable for packet loss testing. // If err != nil, we skip it and just report a warning. - err = analyzer.Run(is.server.Host, func(packetLoss *transport.PLoss) { - if packetLoss != nil && packetLoss.Sent != 0 { - pLoss = packetLoss.Loss() - } + err = analyzer.Run(is.server.Host, func(pl *transport.PLoss) { + pLoss = pl }) if err != nil { is.Log.Warnf("packet loss test failed: %s", err) } } - lossPercent := 0.0 - if pLoss == -1 { - // If all servers are not applicable, returned -1. - lossPercent = -1 - } else { - lossPercent = pLoss * 100.0 + packetLoss := -1.0 + if pLoss != nil { + packetLoss = pLoss.LossPercent() } fields := map[string]any{ @@ -140,7 +135,7 @@ func (is *InternetSpeed) Gather(acc telegraf.Accumulator) error { "upload": is.server.ULSpeed.Mbps(), "latency": timeDurationMillisecondToFloat64(is.server.Latency), "jitter": timeDurationMillisecondToFloat64(is.server.Jitter), - "packet_loss": lossPercent, + "packet_loss": packetLoss, "location": is.server.Name, } tags := map[string]string{