From 14404e7512b774f00ac9a8991c4de1e6d43849a1 Mon Sep 17 00:00:00 2001 From: Anderson Queiroz Date: Wed, 13 Sep 2023 12:06:49 +0200 Subject: [PATCH] metricbeat: collect total thread count per process Upgrades elastic-agent-system-metrics to v0.5.0 in order to collect the total thread count per process. --- CHANGELOG.next.asciidoc | 3 +++ NOTICE.txt | 6 +++--- go.mod | 2 ++ go.sum | 4 ++-- metricbeat/module/system/process/_meta/fields.yml | 10 ++++++++-- metricbeat/module/system/process/process.go | 2 +- metricbeat/module/system/process/process_test.go | 6 +++++- 7 files changed, 24 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 5e609d5daa8b..063d09091be4 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -25,6 +25,9 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff] *Metricbeat* + - System module now collects the total thread count per process. +The elastic-agent-system-metrics was updated to v0.5.0 as the total thread count +is collected by it. *Osquerybeat* diff --git a/NOTICE.txt b/NOTICE.txt index 2d20996227d8..65c2d37e0270 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -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-20230913114254-ef72b6fa59d9 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-20230913114254-ef72b6fa59d9/LICENSE.txt: Apache License Version 2.0, January 2004 diff --git a/go.mod b/go.mod index cfbc0ddeb938..29a1a28012ca 100644 --- a/go.mod +++ b/go.mod @@ -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-20230913114254-ef72b6fa59d9 diff --git a/go.sum b/go.sum index 93222d899eea..216804b1265d 100644 --- a/go.sum +++ b/go.sum @@ -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-20230913114254-ef72b6fa59d9 h1:aK888FnVMPSUNvP6q+9JUj76wOA0INWY/mXR2e6zmAU= +github.com/AndersonQ/elastic-agent-system-metrics v0.0.0-20230913114254-ef72b6fa59d9/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= @@ -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= diff --git a/metricbeat/module/system/process/_meta/fields.yml b/metricbeat/module/system/process/_meta/fields.yml index 65d96ee839d0..e9e20f1b57bd 100644 --- a/metricbeat/module/system/process/_meta/fields.yml +++ b/metricbeat/module/system/process/_meta/fields.yml @@ -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: > @@ -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. @@ -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 diff --git a/metricbeat/module/system/process/process.go b/metricbeat/module/system/process/process.go index 2274f1846d6d..b67ce137bd9b 100644 --- a/metricbeat/module/system/process/process.go +++ b/metricbeat/module/system/process/process.go @@ -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, diff --git a/metricbeat/module/system/process/process_test.go b/metricbeat/module/system/process/process_test.go index f1a29648477a..d9f57f2e3fee 100644 --- a/metricbeat/module/system/process/process_test.go +++ b/metricbeat/module/system/process/process_test.go @@ -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" @@ -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) @@ -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()) }