Skip to content

Commit

Permalink
Minimize call to collect uptime in system input (#5592)
Browse files Browse the repository at this point in the history
(cherry picked from commit 6a97b25)
  • Loading branch information
glinton authored and danielnelson committed Mar 18, 2019
1 parent 81b618b commit a354e7c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions plugins/inputs/system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ func (_ *SystemStats) Gather(acc telegraf.Accumulator) error {
now := time.Now()
acc.AddGauge("system", fields, nil, now)

hostinfo, err := host.Info()
uptime, err := host.Uptime()
if err != nil {
return err
}

acc.AddCounter("system", map[string]interface{}{
"uptime": hostinfo.Uptime,
"uptime": uptime,
}, nil, now)
acc.AddFields("system", map[string]interface{}{
"uptime_format": format_uptime(hostinfo.Uptime),
"uptime_format": formatUptime(uptime),
}, nil, now)

return nil
}

func format_uptime(uptime uint64) string {
func formatUptime(uptime uint64) string {
buf := new(bytes.Buffer)
w := bufio.NewWriter(buf)

Expand Down

0 comments on commit a354e7c

Please sign in to comment.