From 6094bc36396246db895b7c66a8828fde0472154b Mon Sep 17 00:00:00 2001 From: Rene Zbinden Date: Wed, 25 May 2016 12:46:14 +0200 Subject: [PATCH] add option to disable dns lookup for chronyc --- CHANGELOG.md | 1 + plugins/inputs/chrony/README.md | 5 +++-- plugins/inputs/chrony/chrony.go | 17 ++++++++++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9053c4285..ef1a639a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Features - [#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 diff --git a/plugins/inputs/chrony/README.md b/plugins/inputs/chrony/README.md index e12506ecb..43eb77757 100644 --- a/plugins/inputs/chrony/README.md +++ b/plugins/inputs/chrony/README.md @@ -40,7 +40,7 @@ is computed for the new frequency, with weights depending on these accuracies. I measurements from the reference source follow a consistent trend, the residual will be driven to zero over time. - Skew - This is the estimated error bound on the frequency. -- Root delay -This is the total of the network path delays to the stratum-1 computer +- Root delay - This is the total of the network path delays to the stratum-1 computer from which the computer is ultimately synchronised. In certain extreme situations, this value can be negative. (This can arise in a symmetric peer arrangement where the computers’ frequencies are not tracking each other and the network delay is very short relative to the @@ -56,7 +56,8 @@ Delete second or Not synchronised. ```toml # Get standard chrony metrics, requires chronyc executable. [[inputs.chrony]] - # no configuration + ## If true, chronyc tries to perform a DNS lookup for the time server. + # dns_lookup = false ``` ### Measurements & Fields: diff --git a/plugins/inputs/chrony/chrony.go b/plugins/inputs/chrony/chrony.go index b4d874e60..51081b87b 100644 --- a/plugins/inputs/chrony/chrony.go +++ b/plugins/inputs/chrony/chrony.go @@ -20,7 +20,8 @@ var ( ) type Chrony struct { - path string + DNSLookup bool `toml:"dns_lookup"` + path string } func (*Chrony) Description() string { @@ -28,14 +29,24 @@ func (*Chrony) Description() 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 { if len(c.path) == 0 { 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) if err != nil { return fmt.Errorf("failed to run command %s: %s - %s", strings.Join(cmd.Args, " "), err, string(out))