move pathe lookup for sadf to init()

This commit is contained in:
Rene Zbinden 2016-04-07 09:18:09 +00:00 committed by Michele Fadda
parent 779f019026
commit 00c777da05
1 changed files with 9 additions and 11 deletions

View File

@ -176,13 +176,6 @@ func (s *Sysstat) Gather(acc telegraf.Accumulator) error {
// Sadc -S <Activity1> -S <Activity2> ... <collectInterval> 2 tmpFile // Sadc -S <Activity1> -S <Activity2> ... <collectInterval> 2 tmpFile
// The above command collects system metrics during <collectInterval> and saves it in binary form to tmpFile. // The above command collects system metrics during <collectInterval> and saves it in binary form to tmpFile.
func (s *Sysstat) collect() error { 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{} options := []string{}
for _, act := range s.Activities { for _, act := range s.Activities {
options = append(options, "-S", act) options = append(options, "-S", act)
@ -315,10 +308,15 @@ func escape(dirty string) string {
} }
func init() { func init() {
inputs.Add("sysstat", func() telegraf.Input { s := Sysstat{
return &Sysstat{
Group: true, Group: true,
Activities: dfltActivities, Activities: dfltActivities,
} }
sadf, _ := exec.LookPath("sadf")
if len(sadf) > 0 {
s.Sadf = sadf
}
inputs.Add("sysstat", func() telegraf.Input {
return &s
}) })
} }