Search for chronyc only when chrony input plugin is enabled (#7005)
This commit is contained in:
parent
d3b89ec51f
commit
5b8c71e61a
|
@ -33,11 +33,16 @@ func (*Chrony) SampleConfig() string {
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Chrony) Gather(acc telegraf.Accumulator) error {
|
func (c *Chrony) Init() error {
|
||||||
if len(c.path) == 0 {
|
var err error
|
||||||
|
c.path, err = exec.LookPath("chronyc")
|
||||||
|
if err != nil {
|
||||||
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")
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Chrony) Gather(acc telegraf.Accumulator) error {
|
||||||
flags := []string{}
|
flags := []string{}
|
||||||
if !c.DNSLookup {
|
if !c.DNSLookup {
|
||||||
flags = append(flags, "-n")
|
flags = append(flags, "-n")
|
||||||
|
@ -120,12 +125,7 @@ func processChronycOutput(out string) (map[string]interface{}, map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
c := Chrony{}
|
|
||||||
path, _ := exec.LookPath("chronyc")
|
|
||||||
if len(path) > 0 {
|
|
||||||
c.path = path
|
|
||||||
}
|
|
||||||
inputs.Add("chrony", func() telegraf.Input {
|
inputs.Add("chrony", func() telegraf.Input {
|
||||||
return &c
|
return &Chrony{}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue