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

Export cpu cores #3192

Merged
merged 6 commits into from
Dec 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ https://github.com/elastic/beats/compare/v5.1.1...master[Check the HEAD diff]
*Metricbeat*
- Kafka module broker matching enhancements. {pull}3129[3129]
- Add a couchbase module with metricsets for node, cluster and bucker. {pull}3081[3081]
- Export number of cores for cpu module. {pull}3192[3192]


*Packetbeat*
Expand Down
8 changes: 8 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -4774,6 +4774,14 @@ The amount of CPU time spent in involuntary wait by the virtual CPU while the hy



[float]
=== system.cpu.cores

type: long

The number of CPU cores.


[float]
=== system.cpu.user.pct

Expand Down
3 changes: 3 additions & 0 deletions metricbeat/metricbeat.template-es2x.json
Original file line number Diff line number Diff line change
Expand Up @@ -2712,6 +2712,9 @@
},
"cpu": {
"properties": {
"cores": {
"type": "long"
},
"idle": {
"properties": {
"pct": {
Expand Down
3 changes: 3 additions & 0 deletions metricbeat/metricbeat.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -2694,6 +2694,9 @@
},
"cpu": {
"properties": {
"cores": {
"type": "long"
},
"idle": {
"properties": {
"pct": {
Expand Down
5 changes: 5 additions & 0 deletions metricbeat/module/system/cpu/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
description: >
`cpu` contains local CPU stats.
fields:
- name: cores
type: long
description: >
The number of CPU cores.

- name: user.pct
type: scaled_float
format: percent
Expand Down
3 changes: 3 additions & 0 deletions metricbeat/module/system/cpu/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ func (m *MetricSet) Fetch() (common.MapStr, error) {
}
m.cpu.AddCpuPercentage(stat)

cpuCores := GetCores()

cpuStat := common.MapStr{
"cores": cpuCores,
"user": common.MapStr{
"pct": stat.UserPercent,
},
Expand Down
8 changes: 8 additions & 0 deletions metricbeat/module/system/cpu/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package cpu

import (
"runtime"

"github.com/elastic/beats/metricbeat/module/system"
sigar "github.com/elastic/gosigar"
)
Expand All @@ -12,6 +14,7 @@ type CPU struct {
LastCpuTimes *CpuTimes
LastCpuTimesList []CpuTimes
CpuTicks bool
Cores int
}

type CpuTimes struct {
Expand Down Expand Up @@ -115,6 +118,11 @@ func GetCpuPercentageList(last, current []CpuTimes) []CpuTimes {
return current
}

func GetCores() int {
cores := runtime.NumCPU()
return cores
}

func (cpu *CPU) AddCpuPercentage(t2 *CpuTimes) {
cpu.LastCpuTimes = GetCpuPercentage(cpu.LastCpuTimes, t2)
}
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/tests/system/test_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_drop_fields(self):
cpu = evt["system"]["cpu"]
print(cpu.keys())
self.assertItemsEqual(self.de_dot([
"system", "user", "softirq", "iowait",
"system", "cores", "user", "softirq", "iowait",
"idle", "irq", "steal", "nice"
]), cpu.keys())

Expand Down
4 changes: 2 additions & 2 deletions metricbeat/tests/system/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import getpass
import os

SYSTEM_CPU_FIELDS = ["idle.pct", "iowait.pct", "irq.pct", "nice.pct",
SYSTEM_CPU_FIELDS = ["cores", "idle.pct", "iowait.pct", "irq.pct", "nice.pct",
"softirq.pct", "steal.pct", "system.pct", "user.pct"]

SYSTEM_CPU_FIELDS_ALL = ["idle.pct", "idle.ticks", "iowait.pct", "iowait.ticks", "irq.pct", "irq.ticks", "nice.pct", "nice.ticks",
SYSTEM_CPU_FIELDS_ALL = ["cores", "idle.pct", "idle.ticks", "iowait.pct", "iowait.ticks", "irq.pct", "irq.ticks", "nice.pct", "nice.ticks",
"softirq.pct", "softirq.ticks", "steal.pct", "steal.ticks", "system.pct", "system.ticks", "user.pct", "user.ticks"]

SYSTEM_LOAD_FIELDS = ["1", "5", "15", "norm.1", "norm.5", "norm.15"]
Expand Down