fix(inputs.internet_speed): rename enable_file_download to match upstream intent (#11877)

This commit is contained in:
Gavin Chappell 2022-09-26 14:24:20 +01:00 committed by GitHub
parent e292ad2b4c
commit 2d124a4dbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 11 deletions

View File

@ -3,6 +3,13 @@
The `Internet Speed Monitor` collects data about the internet speed on the The `Internet Speed Monitor` collects data about the internet speed on the
system. system.
On some systems, the default settings may cause speed tests to fail; if this
affects you then try enabling `memory_saving_mode`. This reduces the memory
requirements for the test, and may reduce the runtime of the test. However,
please be aware that this may also reduce the accuracy of the test for fast
(>30Mb/s) connections. This setting enables the upstream
[Memory Saving Mode](https://github.com/showwin/speedtest-go#memory-saving-mode)
## Configuration ## Configuration
```toml @sample.conf ```toml @sample.conf
@ -13,8 +20,8 @@ system.
## demand on your internet connection. ## demand on your internet connection.
# interval = "60m" # interval = "60m"
## Sets if runs file download test ## Enable to reduce memory usage
# enable_file_download = false # memory_saving_mode = false
## Caches the closest server location ## Caches the closest server location
# cache = false # cache = false

View File

@ -17,7 +17,8 @@ var sampleConfig string
// InternetSpeed is used to store configuration values. // InternetSpeed is used to store configuration values.
type InternetSpeed struct { type InternetSpeed struct {
EnableFileDownload bool `toml:"enable_file_download"` EnableFileDownload bool `toml:"enable_file_download" deprecated:"1.25.0;use 'memory_saving_mode' instead"`
MemorySavingMode bool `toml:"memory_saving_mode"`
Cache bool `toml:"cache"` Cache bool `toml:"cache"`
Log telegraf.Logger `toml:"-"` Log telegraf.Logger `toml:"-"`
serverCache *speedtest.Server serverCache *speedtest.Server
@ -29,6 +30,12 @@ func (*InternetSpeed) SampleConfig() string {
return sampleConfig return sampleConfig
} }
func (is *InternetSpeed) Init() error {
is.MemorySavingMode = is.MemorySavingMode || is.EnableFileDownload
return nil
}
func (is *InternetSpeed) Gather(acc telegraf.Accumulator) error { func (is *InternetSpeed) Gather(acc telegraf.Accumulator) error {
// Get closest server // Get closest server
s := is.serverCache s := is.serverCache
@ -58,13 +65,15 @@ func (is *InternetSpeed) Gather(acc telegraf.Accumulator) error {
return fmt.Errorf("ping test failed: %v", err) return fmt.Errorf("ping test failed: %v", err)
} }
is.Log.Debug("Running Download...") is.Log.Debug("Running Download...")
err = s.DownloadTest(is.EnableFileDownload) err = s.DownloadTest(is.MemorySavingMode)
if err != nil { if err != nil {
is.Log.Debug("try `memory_saving_mode = true` if this fails consistently")
return fmt.Errorf("download test failed: %v", err) return fmt.Errorf("download test failed: %v", err)
} }
is.Log.Debug("Running Upload...") is.Log.Debug("Running Upload...")
err = s.UploadTest(is.EnableFileDownload) err = s.UploadTest(is.MemorySavingMode)
if err != nil { if err != nil {
is.Log.Debug("try `memory_saving_mode = true` if this fails consistently")
return fmt.Errorf("upload test failed failed: %v", err) return fmt.Errorf("upload test failed failed: %v", err)
} }

View File

@ -12,8 +12,8 @@ func TestGathering(t *testing.T) {
t.Skip("Skipping network-dependent test in short mode.") t.Skip("Skipping network-dependent test in short mode.")
} }
internetSpeed := &InternetSpeed{ internetSpeed := &InternetSpeed{
EnableFileDownload: true, MemorySavingMode: true,
Log: testutil.Logger{}, Log: testutil.Logger{},
} }
acc := &testutil.Accumulator{} acc := &testutil.Accumulator{}
@ -26,8 +26,8 @@ func TestDataGen(t *testing.T) {
t.Skip("Skipping network-dependent test in short mode.") t.Skip("Skipping network-dependent test in short mode.")
} }
internetSpeed := &InternetSpeed{ internetSpeed := &InternetSpeed{
EnableFileDownload: true, MemorySavingMode: true,
Log: testutil.Logger{}, Log: testutil.Logger{},
} }
acc := &testutil.Accumulator{} acc := &testutil.Accumulator{}

View File

@ -5,8 +5,8 @@
## demand on your internet connection. ## demand on your internet connection.
# interval = "60m" # interval = "60m"
## Sets if runs file download test ## Enable to reduce memory usage
# enable_file_download = false # memory_saving_mode = false
## Caches the closest server location ## Caches the closest server location
# cache = false # cache = false