Skip to content

Commit

Permalink
Make system process metricset honor cpu_ticks config option (elastic#…
Browse files Browse the repository at this point in the history
…3776)

When `cpu_ticks` is true in the config file, the system process metricset will report the number of “ticks” (actually jiffies on linux) used in user space (`system.process.cpu.user`), system (`system.process.cpu.system`), and total (`system.process.cpu.total.ticks`).

Fixes elastic#3590
(cherry picked from commit 92fa6c4)
  • Loading branch information
andrewkroh authored and Tudor Golubenco committed Apr 12, 2017
1 parent e67fe07 commit 123ac26
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
26 changes: 10 additions & 16 deletions metricbeat/module/system/process/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,23 +234,17 @@ func (procStats *ProcStats) GetProcessEvent(process *Process, last *Process) com
proc["env"] = process.Env
}

proc["cpu"] = common.MapStr{
"total": common.MapStr{
"pct": GetProcCpuPercentage(last, process),
},
"start_time": unixTimeMsToTime(process.Cpu.StartTime),
}

if procStats.CpuTicks {
proc["cpu"] = common.MapStr{
"user": process.Cpu.User,
"system": process.Cpu.Sys,
"total": common.MapStr{
"ticks": process.Cpu.Total,
"pct": GetProcCpuPercentage(last, process),
},
"start_time": unixTimeMsToTime(process.Cpu.StartTime),
}
} else {
proc["cpu"] = common.MapStr{
"total": common.MapStr{
"pct": GetProcCpuPercentage(last, process),
},
"start_time": unixTimeMsToTime(process.Cpu.StartTime),
}
proc.Put("cpu.user", process.Cpu.User)
proc.Put("cpu.system", process.Cpu.Sys)
proc.Put("cpu.total.ticks", process.Cpu.Total)
}

if process.FD != (sigar.ProcFDUsage{}) {
Expand Down
2 changes: 2 additions & 0 deletions metricbeat/module/system/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
Procs []string `config:"processes"`
Cgroups *bool `config:"process.cgroups.enabled"`
EnvWhitelist []string `config:"process.env.whitelist"`
CPUTicks bool `config:"cpu_ticks"`
}{
Procs: []string{".*"}, // collect all processes by default
}
Expand All @@ -49,6 +50,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
stats: &ProcStats{
Procs: config.Procs,
EnvWhitelist: config.EnvWhitelist,
CpuTicks: config.CPUTicks,
},
}
err := m.stats.InitProcStats()
Expand Down

0 comments on commit 123ac26

Please sign in to comment.