From 3b296e2ab2e1721ba5a4ee34b1b9b1393e0064d0 Mon Sep 17 00:00:00 2001 From: Shirou WAKAYAMA Date: Wed, 23 Apr 2014 17:39:19 +0900 Subject: [PATCH] add steal, guest, guest_nice to cpu_times in linux. --- cpu_linux.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cpu_linux.go b/cpu_linux.go index 2054ed9..8367527 100644 --- a/cpu_linux.go +++ b/cpu_linux.go @@ -40,7 +40,19 @@ func Cpu_times() ([]CPU_TimesStat, error) { Iowait: iowait, Irq: irq, Softirq: softirq, - Stolen: stolen, + Stolen: stolen, + } + if len(fields) > 9 { // Linux >= 2.6.11 + steal, _ := strconv.ParseUint(fields[9], 10, 64) + ct.Steal = steal + } + if len(fields) > 10 { // Linux >= 2.6.24 + guest, _ := strconv.ParseUint(fields[10], 10, 64) + ct.Guest = guest + } + if len(fields) > 11 { // Linux >= 3.2.0 + guest_nice, _ := strconv.ParseUint(fields[11], 10, 64) + ct.Guest_nice = guest_nice } ret = append(ret, ct)