Skip to content

Commit

Permalink
metricbeat: collect number of threads per process
Browse files Browse the repository at this point in the history
Upgrades elastic-agent-system-metrics to v0.5.0 in order to collect the number of threads per process.
  • Loading branch information
AndersonQ committed Sep 26, 2023
1 parent ccfa54a commit 18e0a67
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]

*Metricbeat*

- System module now collects the number of threads per process.
The elastic-agent-system-metrics was updated to v0.5.0 as the number of threads
is collected by it.

*Osquerybeat*

Expand Down
6 changes: 3 additions & 3 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13025,12 +13025,12 @@ these terms.


--------------------------------------------------------------------------------
Dependency : github.com/elastic/elastic-agent-system-metrics
Version: v0.6.1
Dependency : github.com/AndersonQ/elastic-agent-system-metrics
Version: v0.0.0-20230913120026-c3fa121ad082
Licence type (autodetected): Apache-2.0
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-system-metrics@v0.6.1/LICENSE.txt:
Contents of probable licence file $GOMODCACHE/github.com/!anderson!q/elastic-agent-system-metrics@v0.0.0-20230913120026-c3fa121ad082/LICENSE.txt:

Apache License
Version 2.0, January 2004
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,5 @@ replace (

// Exclude this version because the version has an invalid checksum.
exclude github.com/docker/distribution v2.8.0+incompatible

replace github.com/elastic/elastic-agent-system-metrics => github.com/AndersonQ/elastic-agent-system-metrics v0.0.0-20230926055627-a33e2d04a748
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zum
git.sr.ht/~sbinet/gg v0.3.1/go.mod h1:KGYtlADtqsqANL9ueOFkWymvzUvLMQllU5Ixo+8v3pc=
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4=
github.com/99designs/keyring v1.2.1/go.mod h1:fc+wB5KTk9wQ9sDx0kFXB3A0MaeGHM9AwRStKOQ5vOA=
github.com/AndersonQ/elastic-agent-system-metrics v0.0.0-20230926055627-a33e2d04a748 h1:ELaKTbNHnjuAlRnJlGR4RY0AwymrENsA9NAqySBYRs8=
github.com/AndersonQ/elastic-agent-system-metrics v0.0.0-20230926055627-a33e2d04a748/go.mod h1:e2jSj1Fnnyhl21p2g52qhYCyyizX9Lup3z2m/3E9kvg=
github.com/Azure/azure-amqp-common-go/v3 v3.2.1 h1:uQyDk81yn5hTP1pW4Za+zHzy97/f4vDz9o1d/exI4j4=
github.com/Azure/azure-amqp-common-go/v3 v3.2.1/go.mod h1:O6X1iYHP7s2x7NjUKsXVhkwWrQhxrd+d8/3rRadj4CI=
github.com/Azure/azure-event-hubs-go/v3 v3.3.15 h1:2yAik9gS5Qjs4Z6EM1B6d0tfZJ506B/0oA08JlRQxb8=
Expand Down Expand Up @@ -657,8 +659,6 @@ github.com/elastic/elastic-agent-libs v0.3.13 h1:qFiBWeBfjsBId+i31rggyW2ZjzA9qBR
github.com/elastic/elastic-agent-libs v0.3.13/go.mod h1:mpSfrigixx8x+uMxWKl4LtdlrKIhZbA4yT2eIeIazUQ=
github.com/elastic/elastic-agent-shipper-client v0.5.1-0.20230228231646-f04347b666f3 h1:sb+25XJn/JcC9/VL8HX4r4QXSUq4uTNzGS2kxOE7u1U=
github.com/elastic/elastic-agent-shipper-client v0.5.1-0.20230228231646-f04347b666f3/go.mod h1:rWarFM7qYxJKsi9WcV6ONcFjH/NA3niDNpTxO+8/GVI=
github.com/elastic/elastic-agent-system-metrics v0.6.1 h1:LCN1lvQTkdUuU/rKlpKyVMDU/G/I8/iZWCaW6K+mo4o=
github.com/elastic/elastic-agent-system-metrics v0.6.1/go.mod h1:Bj8XM/uNKm553blQHkGNEICRLGnVEtw8yttmV5vBngA=
github.com/elastic/elastic-transport-go/v8 v8.0.0-20230329154755-1a3c63de0db6/go.mod h1:87Tcz8IVNe6rVSLdBux1o/PEItLtyabHU3naC7IoqKI=
github.com/elastic/elastic-transport-go/v8 v8.3.0 h1:DJGxovyQLXGr62e9nDMPSxRyWION0Bh6d9eCFBriiHo=
github.com/elastic/elastic-transport-go/v8 v8.3.0/go.mod h1:87Tcz8IVNe6rVSLdBux1o/PEItLtyabHU3naC7IoqKI=
Expand Down
5 changes: 3 additions & 2 deletions libbeat/generator/fields/module_fields_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package fields

import (
"io/ioutil"
"os"
"path/filepath"
)

Expand All @@ -30,9 +31,9 @@ var indentByModule = map[string]int{
"protos": 8,
}

// GetModules returns a the list of modules for the given modules directory
// GetModules returns a list of modules for the given modules directory
func GetModules(modulesDir string) ([]string, error) {
moduleInfos, err := ioutil.ReadDir(modulesDir)
moduleInfos, err := os.ReadDir(modulesDir)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion libbeat/tests/system/beat/beat.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ def extract_fields(doc_list, name):
if not os.path.isfile(path):
path = os.path.abspath(os.path.dirname(
__file__) + "../../../../_meta/fields.common.yml")

with open(path, encoding="utf-8") as f2:
content = f2.read()

Expand Down Expand Up @@ -788,7 +789,7 @@ def output_count(self, pred, output_file=None):
def assert_fields_are_documented(self, evt):
"""
Assert that all keys present in evt are documented in fields.yml.
This reads from the global fields.yml, means `make collect` has to be run before the check.
This reads from the global fields.yml, means `mage fields` has to be run before the check.
"""
expected_fields, dict_fields, aliases = self.load_fields()
flat = self.flatten_object(evt, dict_fields)
Expand Down
24 changes: 24 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -60655,6 +60655,18 @@ format: percent

--

*`process.num_threads`*::
+
--
The number of threads in the process.


type: integer

format: number

--

[float]
=== system

Expand Down Expand Up @@ -62020,6 +62032,18 @@ alias to: process.pgid

--

*`system.process.num_threads`*::
+
--
Number of threads in the process


type: alias

alias to: process.num_threads

--

*`system.process.cmdline`*::
+
--
Expand Down
5 changes: 5 additions & 0 deletions metricbeat/module/system/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
format: percent
description: >
The percentage of memory the process occupied in main memory (RAM).
- name: num_threads
type: integer
format: number
description: >
The number of threads in the process.
- 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.

10 changes: 8 additions & 2 deletions metricbeat/module/system/process/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
type: alias
path: process.pgid
migration: true
- name: num_threads
type: alias
description: >
Number of threads in the process
path: process.num_threads
migration: true
- name: cmdline
type: keyword
description: >
Expand Down Expand Up @@ -345,7 +351,7 @@
- name: stats.user.pct
type: scaled_float
description: time the cgroup spent in user space, as a percentage of total CPU time

- name: stats.user.norm.pct
type: scaled_float
description: time the cgroup spent in user space, as a percentage of total CPU time, normalized by CPU count.
Expand Down Expand Up @@ -419,7 +425,7 @@
type: long
format: bytes
description: memory max threshhold

- name: mem.events
type: group
description: number of times the controller tripped a given usage level
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/system/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/elastic/elastic-agent-system-metrics/metric/system/resolve"
)

var debugf = logp.MakeDebug("system.process")
var debugf = logp.NewLogger("system.process").Debugf

func init() {
mb.Registry.MustAddMetricSet("system", "process", New,
Expand Down
6 changes: 5 additions & 1 deletion metricbeat/module/system/process/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing"
_ "github.com/elastic/beats/v7/metricbeat/module/system"
Expand All @@ -32,7 +33,9 @@ import (
)

func TestFetch(t *testing.T) {
logp.DevelopmentSetup()
err := logp.DevelopmentSetup()
require.NoError(t, err, "could not set the logger to DevelopmentSetup")

f := mbtest.NewReportingMetricSetV2Error(t, getConfig())
events, errs := mbtest.ReportingFetchV2Error(f)
assert.Empty(t, errs)
Expand All @@ -44,6 +47,7 @@ func TestFetch(t *testing.T) {
assert.Empty(t, errs)
assert.NotEmpty(t, events)

t.Logf("fetched %d events, showing events[0]:", len(events))
t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(),
events[0].BeatEvent("system", "process").Fields.StringToPrint())
}
Expand Down

0 comments on commit 18e0a67

Please sign in to comment.