mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 02:15:43 +03:00
Fixed calculation of cpu usage percent in user and sys mode for pids
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user