Moving the Duration wrapper to it's own package to break import loops.
This commit is contained in:
parent
d77cfd6ecc
commit
0299a17da1
9
agent.go
9
agent.go
|
@ -8,6 +8,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/influxdb/telegraf/duration"
|
||||||
"github.com/influxdb/telegraf/outputs"
|
"github.com/influxdb/telegraf/outputs"
|
||||||
"github.com/influxdb/telegraf/plugins"
|
"github.com/influxdb/telegraf/plugins"
|
||||||
|
|
||||||
|
@ -29,10 +30,10 @@ type runningPlugin struct {
|
||||||
type Agent struct {
|
type Agent struct {
|
||||||
|
|
||||||
// Interval at which to gather information
|
// Interval at which to gather information
|
||||||
Interval Duration
|
Interval duration.Duration
|
||||||
|
|
||||||
// Interval at which to flush data
|
// Interval at which to flush data
|
||||||
FlushInterval Duration
|
FlushInterval duration.Duration
|
||||||
|
|
||||||
// FlushRetries is the number of times to retry each data flush
|
// FlushRetries is the number of times to retry each data flush
|
||||||
FlushRetries int
|
FlushRetries int
|
||||||
|
@ -62,8 +63,8 @@ type Agent struct {
|
||||||
func NewAgent(config *Config) (*Agent, error) {
|
func NewAgent(config *Config) (*Agent, error) {
|
||||||
agent := &Agent{
|
agent := &Agent{
|
||||||
Tags: make(map[string]string),
|
Tags: make(map[string]string),
|
||||||
Interval: Duration{10 * time.Second},
|
Interval: duration.Duration{10 * time.Second},
|
||||||
FlushInterval: Duration{10 * time.Second},
|
FlushInterval: duration.Duration{10 * time.Second},
|
||||||
FlushRetries: 2,
|
FlushRetries: 2,
|
||||||
UTC: true,
|
UTC: true,
|
||||||
Precision: "s",
|
Precision: "s",
|
||||||
|
|
17
config.go
17
config.go
|
@ -15,23 +15,6 @@ import (
|
||||||
"github.com/naoina/toml/ast"
|
"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
|
// 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
|
// will be logging to, as well as all the plugins that the user has
|
||||||
// specified
|
// specified
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -9,13 +9,13 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/influxdb/influxdb/client/v2"
|
"github.com/influxdb/influxdb/client/v2"
|
||||||
t "github.com/influxdb/telegraf"
|
"github.com/influxdb/telegraf/duration"
|
||||||
"github.com/influxdb/telegraf/outputs"
|
"github.com/influxdb/telegraf/outputs"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Datadog struct {
|
type Datadog struct {
|
||||||
Apikey string
|
Apikey string
|
||||||
Timeout t.Duration
|
Timeout duration.Duration
|
||||||
|
|
||||||
apiUrl string
|
apiUrl string
|
||||||
client *http.Client
|
client *http.Client
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/influxdb/influxdb/client/v2"
|
"github.com/influxdb/influxdb/client/v2"
|
||||||
t "github.com/influxdb/telegraf"
|
"github.com/influxdb/telegraf/duration"
|
||||||
"github.com/influxdb/telegraf/outputs"
|
"github.com/influxdb/telegraf/outputs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ type InfluxDB struct {
|
||||||
Database string
|
Database string
|
||||||
UserAgent string
|
UserAgent string
|
||||||
Precision string
|
Precision string
|
||||||
Timeout t.Duration
|
Timeout duration.Duration
|
||||||
|
|
||||||
conns []client.Client
|
conns []client.Client
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
paho "git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.golang.git"
|
paho "git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.golang.git"
|
||||||
"github.com/influxdb/influxdb/client/v2"
|
"github.com/influxdb/influxdb/client/v2"
|
||||||
t "github.com/influxdb/telegraf"
|
"github.com/influxdb/telegraf/duration"
|
||||||
"github.com/influxdb/telegraf/outputs"
|
"github.com/influxdb/telegraf/outputs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ type MQTT struct {
|
||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
Database string
|
Database string
|
||||||
Timeout t.Duration
|
Timeout duration.Duration
|
||||||
TopicPrefix string
|
TopicPrefix string
|
||||||
|
|
||||||
Client *paho.Client
|
Client *paho.Client
|
||||||
|
|
Loading…
Reference in New Issue