Skip to content

Commit

Permalink
Duplicate fields from system.process to process.* (#22845)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiyan-sheng authored Dec 5, 2020
1 parent 86fc865 commit 02cf564
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 173 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Add io.ops in fields exported by system.diskio. {pull}22066[22066]
- `kibana` module: `stats` metricset no-longer collects usage-related data. {pull}22732[22732]
- Adjust the Apache status fields in the fleet mode. {pull}22821[22821]
- Add process.state, process.cpu.pct, process.cpu.start_time and process.memory.pct. {pull}22845[22845]

*Packetbeat*

Expand Down
51 changes: 51 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -41346,6 +41346,57 @@ System status metrics, like CPU and memory usage, that are collected from the op



[float]
=== process

Process metrics.



*`process.state`*::
+
--
The process state. For example: "running".


type: keyword

--

*`process.cpu.pct`*::
+
--
The percentage of CPU time spent by the process since the last event. This value is normalized by the number of CPU cores and it ranges from 0 to 1.


type: scaled_float

format: percent

--

*`process.cpu.start_time`*::
+
--
The time when the process was started.


type: date

--

*`process.memory.pct`*::
+
--
The percentage of memory the process occupied in main memory (RAM).


type: scaled_float

format: percent

--

[float]
=== system

Expand Down
25 changes: 25 additions & 0 deletions metricbeat/module/system/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,31 @@
short_config: true
release: ga
fields:
- name: process
type: group
description: >
Process metrics.
fields:
- name: state
type: keyword
description: >
The process state. For example: "running".
- name: cpu.pct
type: scaled_float
format: percent
description: >
The percentage of CPU time spent by the process since the last event.
This value is normalized by the number of CPU cores and it ranges
from 0 to 1.
- name: cpu.start_time
type: date
description: >
The time when the process was started.
- name: memory.pct
type: scaled_float
format: percent
description: >
The percentage of memory the process occupied in main memory (RAM).
- name: system
type: group
description: >
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/system/fields.go

Large diffs are not rendered by default.

183 changes: 14 additions & 169 deletions metricbeat/module/system/process/_meta/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,197 +15,42 @@
"splash"
],
"command_line": "/sbin/init splash",
"cpu": {
"pct": 0,
"start_time": "2020-12-04T22:17:35.000Z"
},
"memory": {
"pct": 0.0004
},
"name": "systemd",
"pgid": 1,
"pid": 1,
"ppid": 0
"ppid": 0,
"state": "sleeping"
},
"service": {
"type": "system"
},
"system": {
"process": {
"cgroup": {
"blkio": {
"id": "init.scope",
"path": "/init.scope",
"total": {
"bytes": 573440,
"ios": 140
}
},
"cpu": {
"cfs": {
"period": {
"us": 100000
},
"quota": {
"us": 0
},
"shares": 1024
},
"id": "init.scope",
"path": "/init.scope",
"rt": {
"period": {
"us": 0
},
"runtime": {
"us": 0
}
},
"stats": {
"periods": 0,
"throttled": {
"ns": 0,
"periods": 0
}
}
},
"cpuacct": {
"id": "init.scope",
"path": "/init.scope",
"percpu": {
"1": 571119313,
"10": 282248474,
"11": 363773369,
"12": 855691122,
"2": 735154670,
"3": 458174215,
"4": 281192882,
"5": 563599363,
"6": 415888016,
"7": 396270851,
"8": 550242795,
"9": 419970811
},
"stats": {
"system": {
"ns": 1700000000
},
"user": {
"ns": 1920000000
}
},
"total": {
"ns": 5893325881
}
},
"id": "init.scope",
"memory": {
"id": "init.scope",
"kmem": {
"failures": 0,
"limit": {
"bytes": 9223372036854771712
},
"usage": {
"bytes": 16871424,
"max": {
"bytes": 17829888
}
}
},
"kmem_tcp": {
"failures": 0,
"limit": {
"bytes": 9223372036854771712
},
"usage": {
"bytes": 0,
"max": {
"bytes": 0
}
}
},
"mem": {
"failures": 0,
"limit": {
"bytes": 9223372036854771712
},
"usage": {
"bytes": 21827584,
"max": {
"bytes": 30121984
}
}
},
"memsw": {
"failures": 0,
"limit": {
"bytes": 0
},
"usage": {
"bytes": 0,
"max": {
"bytes": 0
}
}
},
"path": "/init.scope",
"stats": {
"active_anon": {
"bytes": 4055040
},
"active_file": {
"bytes": 405504
},
"cache": {
"bytes": 643072
},
"hierarchical_memory_limit": {
"bytes": 9223372036854771712
},
"hierarchical_memsw_limit": {
"bytes": 0
},
"inactive_anon": {
"bytes": 270336
},
"inactive_file": {
"bytes": 0
},
"major_page_faults": 0,
"mapped_file": {
"bytes": 0
},
"page_faults": 117447,
"pages_in": 52008,
"pages_out": 50851,
"rss": {
"bytes": 4009984
},
"rss_huge": {
"bytes": 0
},
"swap": {
"bytes": 0
},
"unevictable": {
"bytes": 0
}
}
},
"path": "/init.scope"
},
"cmdline": "/sbin/init splash",
"cpu": {
"start_time": "2020-11-03T17:55:56.000Z",
"start_time": "2020-12-04T22:17:35.000Z",
"total": {
"norm": {
"pct": 0
},
"pct": 0,
"value": 5580
"value": 1290
}
},
"memory": {
"rss": {
"bytes": 13414400,
"bytes": 12173312,
"pct": 0.0004
},
"share": 8531968,
"size": 173076480
"share": 8679424,
"size": 172113920
},
"state": "sleeping"
}
Expand Down
26 changes: 23 additions & 3 deletions metricbeat/module/system/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,19 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error {
}

// Duplicate system.process.cmdline with ECS name process.command_line
if v, ok := proc["cmdline"]; ok {
rootFields.Put("process.command_line", v)
}
rootFields = getAndCopy(proc, "cmdline", rootFields, "process.command_line")

// Duplicate system.process.state with process.state
rootFields = getAndCopy(proc, "state", rootFields, "process.state")

// Duplicate system.process.cpu.start_time with process.cpu.start_time
rootFields = getAndCopy(proc, "cpu.start_time", rootFields, "process.cpu.start_time")

// Duplicate system.process.cpu.total.norm.pct with process.cpu.pct
rootFields = getAndCopy(proc, "cpu.total.norm.pct", rootFields, "process.cpu.pct")

// Duplicate system.process.memory.rss.pct with process.memory.pct
rootFields = getAndCopy(proc, "memory.rss.pct", rootFields, "process.memory.pct")

if cwd := getAndRemove(proc, "cwd"); cwd != nil {
rootFields.Put("process.working_directory", cwd)
Expand Down Expand Up @@ -180,3 +190,13 @@ func getAndRemove(from common.MapStr, field string) interface{} {
}
return nil
}

func getAndCopy(from common.MapStr, field string, to common.MapStr, toField string) common.MapStr {
v, err := from.GetValue(field)
if err != nil {
return to
}

_, err = to.Put(toField, v)
return to
}

0 comments on commit 02cf564

Please sign in to comment.