add option to disable dns lookup for chronyc
This commit is contained in:
parent
1ef5599361
commit
6094bc3639
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -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))
|
||||||
|
|
Loading…
Reference in New Issue