From 6a97b259ebdd6e483c4a5aa38a60f097a88d43fb Mon Sep 17 00:00:00 2001 From: Greg <2653109+glinton@users.noreply.github.com> Date: Mon, 18 Mar 2019 12:07:44 -0600 Subject: [PATCH] Minimize call to collect uptime in system input (#5592) --- plugins/inputs/system/system.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/inputs/system/system.go b/plugins/inputs/system/system.go index ad17c56ed..55ebbc59e 100644 --- a/plugins/inputs/system/system.go +++ b/plugins/inputs/system/system.go @@ -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)