diff --git a/client/driver/executor/executor.go b/client/driver/executor/executor.go index 582a4cefd..37df9cb32 100644 --- a/client/driver/executor/executor.go +++ b/client/driver/executor/executor.go @@ -135,8 +135,10 @@ type ProcessState struct { // nomadPid holds a pid and it's cpu percentage calculator type nomadPid struct { - pid int - cpuStats *stats.CpuStats + pid int + cpuStatsTotal *stats.CpuStats + cpuStatsUser *stats.CpuStats + cpuStatsSys *stats.CpuStats } // SyslogServerState holds the address and islation information of a launched @@ -506,11 +508,11 @@ func (e *UniversalExecutor) pidStats() (map[string]*cstructs.ResourceUsage, erro cs := &cstructs.CpuStats{} if cpuStats, err := p.Times(); err == nil { - cs.SystemMode = cpuStats.System - cs.UserMode = cpuStats.User + cs.SystemMode = pid.cpuStatsSys.Percent(cpuStats.System) + cs.UserMode = pid.cpuStatsUser.Percent(cpuStats.User) // calculate cpu usage percent - cs.Percent = pid.cpuStats.Percent(cpuStats.Total()) + cs.Percent = pid.cpuStatsTotal.Percent(cpuStats.Total()) } stats[strconv.Itoa(pid.pid)] = &cstructs.ResourceUsage{MemoryStats: ms, CpuStats: cs} } @@ -739,7 +741,7 @@ func (e *UniversalExecutor) scanPids(parentPid int, allPids []ps.Process) ([]*no } res := make([]*nomadPid, 0, len(processFamily)) for pid := range processFamily { - res = append(res, &nomadPid{pid, stats.NewCpuStats()}) + res = append(res, &nomadPid{pid, stats.NewCpuStats(), stats.NewCpuStats(), stats.NewCpuStats()}) } return res, nil } diff --git a/client/driver/executor/executor_linux.go b/client/driver/executor/executor_linux.go index 45f52cb38..0aac80929 100644 --- a/client/driver/executor/executor_linux.go +++ b/client/driver/executor/executor_linux.go @@ -271,7 +271,7 @@ func (e *UniversalExecutor) getAllPids() ([]*nomadPid, error) { } np := make([]*nomadPid, len(pids)) for idx, pid := range pids { - np[idx] = &nomadPid{pid, stats.NewCpuStats()} + np[idx] = &nomadPid{pid, stats.NewCpuStats(), stats.NewCpuStats(), stats.NewCpuStats()} } return np, nil }