add option to disable dns lookup for chronyc

This commit is contained in:
Rene Zbinden 2016-05-25 12:46:14 +02:00
parent 1ef5599361
commit 6094bc3639
3 changed files with 18 additions and 5 deletions

View File

@ -5,6 +5,7 @@
### Features ### Features
- [#1247](https://github.com/influxdata/telegraf/pull/1247): rollbar input plugin. Thanks @francois2metz and @cduez! - [#1247](https://github.com/influxdata/telegraf/pull/1247): rollbar input plugin. Thanks @francois2metz and @cduez!
- [#1265](https://github.com/influxdata/telegraf/pull/1265): Make dns lookups for chrony configurable. Thanks @zbindenren!
### Bugfixes ### Bugfixes

View File

@ -56,7 +56,8 @@ Delete second or Not synchronised.
```toml ```toml
# Get standard chrony metrics, requires chronyc executable. # Get standard chrony metrics, requires chronyc executable.
[[inputs.chrony]] [[inputs.chrony]]
# no configuration ## If true, chronyc tries to perform a DNS lookup for the time server.
# dns_lookup = false
``` ```
### Measurements & Fields: ### Measurements & Fields:

View File

@ -20,6 +20,7 @@ var (
) )
type Chrony struct { type Chrony struct {
DNSLookup bool `toml:"dns_lookup"`
path string path string
} }
@ -28,14 +29,24 @@ func (*Chrony) Description() string {
} }
func (*Chrony) SampleConfig() string { func (*Chrony) SampleConfig() string {
return "" return `
## If true, chronyc tries to perform a DNS lookup for the time server.
# dns_lookup = false
`
} }
func (c *Chrony) Gather(acc telegraf.Accumulator) error { func (c *Chrony) Gather(acc telegraf.Accumulator) error {
if len(c.path) == 0 { if len(c.path) == 0 {
return errors.New("chronyc not found: verify that chrony is installed and that chronyc is in your PATH") return errors.New("chronyc not found: verify that chrony is installed and that chronyc is in your PATH")
} }
cmd := execCommand(c.path, "tracking")
flags := []string{}
if !c.DNSLookup {
flags = append(flags, "-n")
}
flags = append(flags, "tracking")
cmd := execCommand(c.path, flags...)
out, err := internal.CombinedOutputTimeout(cmd, time.Second*5) out, err := internal.CombinedOutputTimeout(cmd, time.Second*5)
if err != nil { if err != nil {
return fmt.Errorf("failed to run command %s: %s - %s", strings.Join(cmd.Args, " "), err, string(out)) return fmt.Errorf("failed to run command %s: %s - %s", strings.Join(cmd.Args, " "), err, string(out))