From 0c9a1d33cbc1eb92dfc0731fae1a05d15773c594 Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Wed, 1 Feb 2017 23:13:59 +0000 Subject: [PATCH] fix panic when /proc/stat is empty don't really know why this would be the case, but I suppose there are always edge-cases. see https://github.com/influxdata/telegraf/issues/2356 --- cpu/cpu_linux.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cpu/cpu_linux.go b/cpu/cpu_linux.go index 1979ebc..bd0ed8a 100644 --- a/cpu/cpu_linux.go +++ b/cpu/cpu_linux.go @@ -36,6 +36,9 @@ func Times(percpu bool) ([]TimesStat, error) { var startIdx uint = 1 for { linen, _ := common.ReadLinesOffsetN(filename, startIdx, 1) + if len(linen) == 0 { + break + } line := linen[0] if !strings.HasPrefix(line, "cpu") { break