From 1d30d9eecd27cfa29b188df59f43485e8e8117b0 Mon Sep 17 00:00:00 2001 From: Ingo Oppermann Date: Wed, 1 Feb 2023 16:24:57 +0100 Subject: [PATCH] Fix use of deprecated function --- psutil/process.go | 2 +- psutil/psutil.go | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/psutil/process.go b/psutil/process.go index 187485d4..1b1ab3bd 100644 --- a/psutil/process.go +++ b/psutil/process.go @@ -98,7 +98,7 @@ func (p *process) cpuTimes() (*cpuTimesStat, error) { } s := &cpuTimesStat{ - total: times.Total(), + total: cpuTotal(times), system: times.System, user: times.User, } diff --git a/psutil/psutil.go b/psutil/psutil.go index dc75d0b9..b2a33a4f 100644 --- a/psutil/psutil.go +++ b/psutil/psutil.go @@ -285,7 +285,7 @@ func (u *util) cpuTimes() (*cpuTimesStat, error) { } s := &cpuTimesStat{ - total: times[0].Total(), + total: cpuTotal(×[0]), system: times[0].System, user: times[0].User, idle: times[0].Idle, @@ -496,3 +496,8 @@ func (u *util) readFile(path string) ([]string, error) { return lines, nil } + +func cpuTotal(c *cpu.TimesStat) float64 { + return c.User + c.System + c.Idle + c.Nice + c.Iowait + c.Irq + + c.Softirq + c.Steal + c.Guest + c.GuestNice +}