Skip to content

Commit

Permalink
Group all cpu usage per core statistics under cpus
Browse files Browse the repository at this point in the history
Add a configuration option to enable adding cpu usage per core. By default is false as there
are too many data exported.
Rename proc option with process (as the type it got changed to process in the last release).
Add an example JSON output
Add a test for cpu_per_core option only on Unix systems
  • Loading branch information
monicasarbu committed Dec 10, 2015
1 parent c23e93a commit a14ecfd
Show file tree
Hide file tree
Showing 13 changed files with 476 additions and 16 deletions.
7 changes: 4 additions & 3 deletions topbeat/beat/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ type TopConfig struct {
Period *int64
Procs *[]string
Stats struct {
System *bool
Proc *bool
Filesystem *bool
System *bool `yaml:"system"`
Proc *bool `yaml:"process"`
Filesystem *bool `yaml:"filesystem"`
CpuPerCore *bool `yaml:"cpu_per_core"`
}
}

Expand Down
23 changes: 18 additions & 5 deletions topbeat/beat/topbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ type Topbeat struct {
TbConfig ConfigSettings
events publisher.Client

sysStats bool
procStats bool
fsStats bool
sysStats bool
procStats bool
fsStats bool
cpuPerCore bool

done chan struct{}
}
Expand Down Expand Up @@ -72,6 +73,11 @@ func (tb *Topbeat) Config(b *beat.Beat) error {
} else {
tb.fsStats = true
}
if tb.TbConfig.Input.Stats.CpuPerCore != nil {
tb.cpuPerCore = *tb.TbConfig.Input.Stats.CpuPerCore
} else {
tb.cpuPerCore = false
}

if !tb.sysStats && !tb.procStats && !tb.fsStats {
return errors.New("Invalid statistics configuration")
Expand All @@ -83,6 +89,7 @@ func (tb *Topbeat) Config(b *beat.Beat) error {
logp.Debug("topbeat", "System statistics %t\n", tb.sysStats)
logp.Debug("topbeat", "Process statistics %t\n", tb.procStats)
logp.Debug("topbeat", "File system statistics %t\n", tb.fsStats)
logp.Debug("topbeat", "Cpu usage per core %t\n", tb.cpuPerCore)

return nil
}
Expand Down Expand Up @@ -263,8 +270,14 @@ func (t *Topbeat) exportSystemStats() error {
"swap": swap_stat,
}

for coreNumber, core := range cpu_core_stat {
event["cpu"+strconv.Itoa(coreNumber)] = core
if t.cpuPerCore {

cpus := common.MapStr{}

for coreNumber, stat := range cpu_core_stat {
cpus["cpu"+strconv.Itoa(coreNumber)] = stat
}
event["cpus"] = cpus
}

t.events.PublishEvent(event)
Expand Down
39 changes: 35 additions & 4 deletions topbeat/docs/configuration.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,19 @@ input:
# Statistics to collect (all enabled by default)
stats:
# per system statistics, by default is true
system: true
proc: true
# per process statistics, by default is true
process: true
# file system information, by default is true
filesystem: true
# cpu usage per core, by default is false
cpu_per_core: false
------------------------------------------------------------------------------

==== Options
Expand All @@ -58,11 +68,32 @@ default, all the running processes are monitored.

The statistics to collect. You can specify the following settings:

* `system: true` to capture system-wide statistics, including statistics about
* `system` to export system-wide statistics, including statistics about
system load, CPU usage, memory usage, and swap usage.
* `proc: true` to capture per-process statistics, such as the process name,
* `process` to export per-process statistics, such as the process name,
parent pid, state, pid, CPU usage, and memory usage.
* `filesystem: true` to capture file system statistics, including details about the
* `filesystem` to export file system statistics, including details about the
mounted disks, such as the total and used disk space, and details about each
disk, such as the device name and the mounting place.
* `cpu_per_core` to export the cpu usage per core. By default is false and it makes sense only if `system: true`.
The details are grouped under `cpus`. For each core of the server, few details are exported like:

[source,json]
----------------------------------------------------------------------------------
"cpus": {
"cpu0": {
"user": 373170,
"user_p": 0,
"nice": 0,
"system": 463408,
"system_p": 0,
"idle": 2904305,
"iowait": 0,
"irq": 0,
"softirq": 0,
"steal": 0
},
...
}
----------------------------------------------------------------------------------

72 changes: 72 additions & 0 deletions topbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,78 @@ type: int
The amount of CPU time spent in involuntary wait by the virtual CPU while the hypervisor was servicing another processor. Available only on Unix.


=== cpus Fields

This group contains cpu usage per core statistics.


=== cpui Fields

This group contains cpu usage statistics of the core i, where i is the core number


==== cpus.cpui.user

type: int

The amount of CPU time spent in user space on core i.


==== cpus.cpui.user_p

type: float

The percentage of CPU time spent in user space on core i.


==== cpus.cpui.nice

type: int

The amount of CPU time spent on low-priority processes on core i.


==== cpus.cpui.system

type: int

The amount of CPU time spent in kernel space on core i.


==== cpus.cpui.system_p

type: float

The percentage of CPU time spent in kernel space on core i.


==== cpus.cpui.idle

type: int

The amount of CPU time spent idle on core i.


==== cpus.cpui.iowait

type: int

The amount of CPU time spent in wait (on disk) on core i.


==== cpus.cpui.softirq

type: int

The amount of CPU time spent servicing and handling software interrupts on core i.

==== cpus.cpui.steal

type: int

The amount of CPU time spent in involuntary wait by the virtual CPU while the hypervisor was servicing another processor on core i. Available only on Unix.


=== mem Fields

This group contains statistics related to the memory usage on the system.
Expand Down
10 changes: 10 additions & 0 deletions topbeat/etc/beat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ input:

# Statistics to collect (all enabled by default)
stats:
# per system statistics, by default is true
system: true

# per process statistics, by default is true
proc: true

# file system information, by default is true
filesystem: true

# cpu usage per core, by default is false
cpu_per_core: false


68 changes: 68 additions & 0 deletions topbeat/etc/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,74 @@ system:
was servicing another processor.
Available only on Unix.
- name: cpus
type: group
description: This group contains cpu usage per core statistics.
fields:
- name: cpui
type: group
description: This group contains cpu usage statistics of the core i, where 0<i<n and n is the number of cores.
fields:

- name: user
path: cpus.cpui.user
type: int
description: >
The amount of CPU time spent in user space on core i.
- name: user_p
path: cpus.cpui.user_p
type: float
description: >
The percentage of CPU time spent in user space on core i.
- name: nice
path: cpus.cpui.nice
type: int
description: >
The amount of CPU time spent on low-priority processes on core i.
- name: system
path: cpus.cpui.system
type: int
description: >
The amount of CPU time spent in kernel space on core i.
- name: system_p
path: cpus.cpui.system_p
type: float
description: >
The percentage of CPU time spent in kernel space on core i.
- name: idle
path: cpus.cpui.idle
type: int
description: >
The amount of CPU time spent idle on core i.
- name: iowait
path: cpus.cpui.iowait
type: int
description: >
The amount of CPU time spent in wait (on disk) on core i.
- name: softirq
path: cpus.cpui.softirq
type: int
description:
The amount of CPU time spent servicing and handling software interrupts on core i.


- name: steal
path: cpus.cpui.steal
type: int
description: >
The amount of CPU time spent in involuntary wait by the virtual CPU while the hypervisor
was servicing another processor on core i.
Available only on Unix.
- name: mem
type: group
Expand Down
10 changes: 10 additions & 0 deletions topbeat/etc/topbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,19 @@ input:

# Statistics to collect (all enabled by default)
stats:
# per system statistics, by default is true
system: true

# per process statistics, by default is true
proc: true

# file system information, by default is true
filesystem: true

# cpu usage per core, by default is false
cpu_per_core: false


###############################################################################
############################# Libbeat Config ##################################
# Base config file used by all other beats for using libbeat features
Expand Down
Loading

0 comments on commit a14ecfd

Please sign in to comment.