From cd39b973a1b8a0cd650d5d037331787762dfa5a2 Mon Sep 17 00:00:00 2001 From: Rene Zbinden Date: Thu, 7 Apr 2016 09:18:09 +0000 Subject: [PATCH] move pathe lookup for sadf to init() --- plugins/inputs/sysstat/sysstat.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/plugins/inputs/sysstat/sysstat.go b/plugins/inputs/sysstat/sysstat.go index 6707f5bdd..d57bd10dc 100644 --- a/plugins/inputs/sysstat/sysstat.go +++ b/plugins/inputs/sysstat/sysstat.go @@ -176,13 +176,6 @@ func (s *Sysstat) Gather(acc telegraf.Accumulator) error { // Sadc -S -S ... 2 tmpFile // The above command collects system metrics during and saves it in binary form to tmpFile. func (s *Sysstat) collect() error { - if len(s.Sadf) == 0 { - sadf, err := exec.LookPath("sadf") - if err != nil { - return errors.New("sadf not in $PATH, configure path to sadf") - } - s.Sadf = sadf - } options := []string{} for _, act := range s.Activities { options = append(options, "-S", act) @@ -315,10 +308,15 @@ func escape(dirty string) string { } func init() { + s := Sysstat{ + Group: true, + Activities: dfltActivities, + } + sadf, _ := exec.LookPath("sadf") + if len(sadf) > 0 { + s.Sadf = sadf + } inputs.Add("sysstat", func() telegraf.Input { - return &Sysstat{ - Group: true, - Activities: dfltActivities, - } + return &s }) }