add option to disable dns lookup for chronyc

closes #1265
This commit is contained in:
Rene Zbinden 2016-05-25 12:46:14 +02:00 committed by Cameron Sparr
parent 9144f9630b
commit a8334c3261
4 changed files with 36 additions and 9 deletions

View File

@ -23,6 +23,7 @@ time before a new metric is included by the plugin.
- [#1208](https://github.com/influxdata/telegraf/pull/1208): Standardized AWS credentials evaluation & wildcard CloudWatch dimensions. Thanks @johnrengelman! - [#1208](https://github.com/influxdata/telegraf/pull/1208): Standardized AWS credentials evaluation & wildcard CloudWatch dimensions. Thanks @johnrengelman!
- [#1264](https://github.com/influxdata/telegraf/pull/1264): Add SSL config options to http_response plugin. - [#1264](https://github.com/influxdata/telegraf/pull/1264): Add SSL config options to http_response plugin.
- [#1272](https://github.com/influxdata/telegraf/pull/1272): graphite parser: add ability to specify multiple tag keys, for consistency with influxdb parser. - [#1272](https://github.com/influxdata/telegraf/pull/1272): graphite parser: add ability to specify multiple tag keys, for consistency with influxdb parser.
- [#1265](https://github.com/influxdata/telegraf/pull/1265): Make dns lookups for chrony configurable. Thanks @zbindenren!
### Bugfixes ### Bugfixes

View File

@ -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 measurements from the reference source follow a consistent trend, the residual will be
driven to zero over time. driven to zero over time.
- Skew - This is the estimated error bound on the frequency. - 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 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 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 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 ```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,7 +20,8 @@ var (
) )
type Chrony struct { type Chrony struct {
path string DNSLookup bool `toml:"dns_lookup"`
path string
} }
func (*Chrony) Description() string { func (*Chrony) Description() 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))

View File

@ -42,6 +42,15 @@ func TestGather(t *testing.T) {
} }
acc.AssertContainsTaggedFields(t, "chrony", fields, tags) acc.AssertContainsTaggedFields(t, "chrony", fields, tags)
// test with dns lookup
c.DNSLookup = true
err = c.Gather(&acc)
if err != nil {
t.Fatal(err)
}
acc.AssertContainsTaggedFields(t, "chrony", fields, tags)
} }
// fackeExecCommand is a helper function that mock // fackeExecCommand is a helper function that mock
@ -63,8 +72,9 @@ func TestHelperProcess(t *testing.T) {
return return
} }
mockData := `Reference ID : 192.168.1.22 (ntp.example.com) lookup := "Reference ID : 192.168.1.22 (ntp.example.com)\n"
Stratum : 3 noLookup := "Reference ID : 192.168.1.22 (192.168.1.22)\n"
mockData := `Stratum : 3
Ref time (UTC) : Thu May 12 14:27:07 2016 Ref time (UTC) : Thu May 12 14:27:07 2016
System time : 0.000020390 seconds fast of NTP time System time : 0.000020390 seconds fast of NTP time
Last offset : +0.000012651 seconds Last offset : +0.000012651 seconds
@ -84,8 +94,12 @@ Leap status : Normal
// /tmp/go-build970079519/…/_test/integration.test -test.run=TestHelperProcess -- // /tmp/go-build970079519/…/_test/integration.test -test.run=TestHelperProcess --
cmd, args := args[3], args[4:] cmd, args := args[3], args[4:]
if cmd == "chronyc" && args[0] == "tracking" { if cmd == "chronyc" {
fmt.Fprint(os.Stdout, mockData) if args[0] == "tracking" {
fmt.Fprint(os.Stdout, lookup+mockData)
} else {
fmt.Fprint(os.Stdout, noLookup+mockData)
}
} else { } else {
fmt.Fprint(os.Stdout, "command not found") fmt.Fprint(os.Stdout, "command not found")
os.Exit(1) os.Exit(1)