diff --git a/agent.go b/agent.go index efa4c9525..00b0c6ace 100644 --- a/agent.go +++ b/agent.go @@ -8,6 +8,7 @@ import ( "sync" "time" + "github.com/influxdb/telegraf/duration" "github.com/influxdb/telegraf/outputs" "github.com/influxdb/telegraf/plugins" @@ -29,10 +30,10 @@ type runningPlugin struct { type Agent struct { // Interval at which to gather information - Interval Duration + Interval duration.Duration // Interval at which to flush data - FlushInterval Duration + FlushInterval duration.Duration // FlushRetries is the number of times to retry each data flush FlushRetries int @@ -62,8 +63,8 @@ type Agent struct { func NewAgent(config *Config) (*Agent, error) { agent := &Agent{ Tags: make(map[string]string), - Interval: Duration{10 * time.Second}, - FlushInterval: Duration{10 * time.Second}, + Interval: duration.Duration{10 * time.Second}, + FlushInterval: duration.Duration{10 * time.Second}, FlushRetries: 2, UTC: true, Precision: "s", diff --git a/config.go b/config.go index 2d2298c19..2c5152ddb 100644 --- a/config.go +++ b/config.go @@ -15,23 +15,6 @@ import ( "github.com/naoina/toml/ast" ) -// Duration just wraps time.Duration -type Duration struct { - time.Duration -} - -// UnmarshalTOML parses the duration from the TOML config file -func (d *Duration) UnmarshalTOML(b []byte) error { - dur, err := time.ParseDuration(string(b[1 : len(b)-1])) - if err != nil { - return err - } - - d.Duration = dur - - return nil -} - // Config specifies the URL/user/password for the database that telegraf // will be logging to, as well as all the plugins that the user has // specified diff --git a/duration/duration.go b/duration/duration.go new file mode 100644 index 000000000..48c4e6193 --- /dev/null +++ b/duration/duration.go @@ -0,0 +1,20 @@ +package duration + +import "time" + +// Duration just wraps time.Duration +type Duration struct { + time.Duration +} + +// UnmarshalTOML parses the duration from the TOML config file +func (d *Duration) UnmarshalTOML(b []byte) error { + dur, err := time.ParseDuration(string(b[1 : len(b)-1])) + if err != nil { + return err + } + + d.Duration = dur + + return nil +} diff --git a/outputs/datadog/datadog.go b/outputs/datadog/datadog.go index 2538b7d40..1476637dd 100644 --- a/outputs/datadog/datadog.go +++ b/outputs/datadog/datadog.go @@ -9,13 +9,13 @@ import ( "sort" "github.com/influxdb/influxdb/client/v2" - t "github.com/influxdb/telegraf" + "github.com/influxdb/telegraf/duration" "github.com/influxdb/telegraf/outputs" ) type Datadog struct { Apikey string - Timeout t.Duration + Timeout duration.Duration apiUrl string client *http.Client diff --git a/outputs/influxdb/influxdb.go b/outputs/influxdb/influxdb.go index 0cd3ca6e0..f40f4f25b 100644 --- a/outputs/influxdb/influxdb.go +++ b/outputs/influxdb/influxdb.go @@ -9,7 +9,7 @@ import ( "strings" "github.com/influxdb/influxdb/client/v2" - t "github.com/influxdb/telegraf" + "github.com/influxdb/telegraf/duration" "github.com/influxdb/telegraf/outputs" ) @@ -22,7 +22,7 @@ type InfluxDB struct { Database string UserAgent string Precision string - Timeout t.Duration + Timeout duration.Duration conns []client.Client } diff --git a/outputs/mqtt/mqtt.go b/outputs/mqtt/mqtt.go index e7b7f9ac8..89eb43109 100644 --- a/outputs/mqtt/mqtt.go +++ b/outputs/mqtt/mqtt.go @@ -11,7 +11,7 @@ import ( paho "git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.golang.git" "github.com/influxdb/influxdb/client/v2" - t "github.com/influxdb/telegraf" + "github.com/influxdb/telegraf/duration" "github.com/influxdb/telegraf/outputs" ) @@ -24,7 +24,7 @@ type MQTT struct { Username string Password string Database string - Timeout t.Duration + Timeout duration.Duration TopicPrefix string Client *paho.Client