From 35ac618950a884ba778f1d3c7c40c2f1bf80aaf7 Mon Sep 17 00:00:00 2001 From: mtojek Date: Wed, 9 Dec 2020 14:38:43 +0100 Subject: [PATCH 1/2] Fleet apache: convert status.total_kbytes to status.total_bytes --- metricbeat/module/apache/status/data.go | 2 +- metricbeat/module/apache/status/status.go | 7 +++++++ .../module/apache/status/status_integration_test.go | 11 +++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/metricbeat/module/apache/status/data.go b/metricbeat/module/apache/status/data.go index 0c57bc34357..fdfab72e0b9 100644 --- a/metricbeat/module/apache/status/data.go +++ b/metricbeat/module/apache/status/data.go @@ -129,7 +129,7 @@ func eventMapping(scanner *bufio.Scanner, hostname string) (common.MapStr, error for scanner.Scan() { if match := matchNumber.FindStringSubmatch(scanner.Text()); len(match) == 3 { // Total Accesses: 16147 - //Total kBytes: 12988 + // Total kBytes: 12988 // Uptime: 3229728 // CPULoad: .000408393 // CPUUser: 0 diff --git a/metricbeat/module/apache/status/status.go b/metricbeat/module/apache/status/status.go index fa6e033ee77..73be8be1ec5 100644 --- a/metricbeat/module/apache/status/status.go +++ b/metricbeat/module/apache/status/status.go @@ -109,6 +109,13 @@ func adjustFleetEvent(event mb.Event) mb.Event { var adjusted mb.Event adjusted.MetricSetFields = event.MetricSetFields.Clone() + // Convert apache.status.total_kbytes to apache.status.total_bytes + totalKBytes, err := adjusted.MetricSetFields.GetValue("total_kbytes") + if err == nil { + adjusted.MetricSetFields.Put("total_bytes", totalKBytes.(int64)*1024) + adjusted.MetricSetFields.Delete("total_kbytes") + } + // Remove apache.hostname adjusted.MetricSetFields.Delete("hostname") return adjusted diff --git a/metricbeat/module/apache/status/status_integration_test.go b/metricbeat/module/apache/status/status_integration_test.go index b5abc0170f6..b441f63e351 100644 --- a/metricbeat/module/apache/status/status_integration_test.go +++ b/metricbeat/module/apache/status/status_integration_test.go @@ -68,8 +68,15 @@ func TestFetchFleetMode(t *testing.T) { t.Fatal("Too few top-level elements in the event") } - _, err := event.MetricSetFields.GetValue("hostname") - assert.Equal(t, common.ErrKeyNotFound, err, "apache.hostname shouldn't be present in the fleet mode") + _, err := event.MetricSetFields.GetValue("total_kbytes") + assert.Equal(t, common.ErrKeyNotFound, err, "apache.status.total_kbytes shouldn't be present in the fleet mode") + + totalBytes, err := event.MetricSetFields.GetValue("total_bytes") + assert.NoError(t, err, "apache.status.total_bytes should be present in the fleet mode") + assert.GreaterOrEqual(t, totalBytes.(int64), int64(0), "apache.status.total_bytes should be non-negative") + + _, err = event.MetricSetFields.GetValue("hostname") + assert.Equal(t, common.ErrKeyNotFound, err, "apache.status.hostname shouldn't be present in the fleet mode") } func getConfig(host string) map[string]interface{} { From ad10da09fc19720aa963e961d4732147ab22b4a8 Mon Sep 17 00:00:00 2001 From: mtojek Date: Wed, 9 Dec 2020 14:56:06 +0100 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.next.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 3ff79966a3e..b16abb2e7f7 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -863,6 +863,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - `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] +- Apache: convert status.total_kbytes to status.total_bytes in fleet mode. {pull}23022[23022] *Packetbeat*