Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cgroup.cpuacct percentages #25057

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
formatting, name cleanup
fearful-symmetry committed Apr 14, 2021
commit 87fe9f1e35c41304e5cfb50a883bde098c443e36
12 changes: 6 additions & 6 deletions libbeat/metric/system/process/cgroup.go
Original file line number Diff line number Diff line change
@@ -108,24 +108,24 @@ func cgroupCPUAccountingToMapStr(process *Process) common.MapStr {
"path": cpuacct.Path,
"total": common.MapStr{
"ns": cpuacct.TotalNanos,
"pct": process.PctStats.CgroupCPUTotalPct,
"pct": process.PctStats.CPUTotalPct,
"norm": common.MapStr{
"pct": process.PctStats.CgroupCPUTotalPctNorm,
"pct": process.PctStats.CPUTotalPctNorm,
},
},
"stats": common.MapStr{
"system": common.MapStr{
"ns": cpuacct.Stats.SystemNanos,
"pct": process.PctStats.CgroupCPUSystemPct,
"pct": process.PctStats.CPUSystemPct,
"norm": common.MapStr{
"pct": process.PctStats.CgroupCPUSystemPctNorm,
"pct": process.PctStats.CPUSystemPctNorm,
},
},
"user": common.MapStr{
"ns": cpuacct.Stats.UserNanos,
"pct": process.PctStats.CgroupCPUUserPct,
"pct": process.PctStats.CPUUserPct,
"norm": common.MapStr{
"pct": process.PctStats.CgroupCPUUserPctNorm,
"pct": process.PctStats.CPUUserPctNorm,
},
},
},
27 changes: 12 additions & 15 deletions libbeat/metric/system/process/process.go
Original file line number Diff line number Diff line change
@@ -72,12 +72,12 @@ type Process struct {

// CgroupPctStats stores rendered percent values from cgroup CPU data
type CgroupPctStats struct {
CgroupCPUTotalPct float64
CgroupCPUTotalPctNorm float64
CgroupCPUUserPct float64
CgroupCPUUserPctNorm float64
CgroupCPUSystemPct float64
CgroupCPUSystemPctNorm float64
CPUTotalPct float64
CPUTotalPctNorm float64
CPUUserPct float64
CPUUserPctNorm float64
CPUSystemPct float64
CPUSystemPctNorm float64
}

// Stats stores the stats of processes on the host.
@@ -403,7 +403,6 @@ func GetProcCPUPercentage(s0, s1 *Process) (normalizedPct, pct, totalPct float64
// as USER_HZ is less precise value that will get rounded up to nanseconds.
// Because of that, `user` and `system` metrics reflect a precentage of overall CPU time, but can't be compared to the total pct values.
func GetCgroupPercentage(s0, s1 *Process) CgroupPctStats {

if s0 == nil || s1 == nil || s0.RawStats == nil || s1.RawStats == nil || s0.RawStats.CPUAccounting == nil || s1.RawStats.CPUAccounting == nil {
return CgroupPctStats{}
}
@@ -433,16 +432,14 @@ func GetCgroupPercentage(s0, s1 *Process) CgroupPctStats {
normalizedSystem := systemPct / float64(cpuCount)

pctValues := CgroupPctStats{
CgroupCPUTotalPct: common.Round(pct, common.DefaultDecimalPlacesCount),
CgroupCPUTotalPctNorm: common.Round(normalizedPct, common.DefaultDecimalPlacesCount),
CgroupCPUUserPct: common.Round(userPct, common.DefaultDecimalPlacesCount),
CgroupCPUUserPctNorm: common.Round(normalizedUser, common.DefaultDecimalPlacesCount),
CgroupCPUSystemPct: common.Round(systemPct, common.DefaultDecimalPlacesCount),
CgroupCPUSystemPctNorm: common.Round(normalizedSystem, common.DefaultDecimalPlacesCount),
CPUTotalPct: common.Round(pct, common.DefaultDecimalPlacesCount),
CPUTotalPctNorm: common.Round(normalizedPct, common.DefaultDecimalPlacesCount),
CPUUserPct: common.Round(userPct, common.DefaultDecimalPlacesCount),
CPUUserPctNorm: common.Round(normalizedUser, common.DefaultDecimalPlacesCount),
CPUSystemPct: common.Round(systemPct, common.DefaultDecimalPlacesCount),
CPUSystemPctNorm: common.Round(normalizedSystem, common.DefaultDecimalPlacesCount),
}

return pctValues

}

// matchProcess checks if the provided process name matches any of the process regexes