Skip to content

Commit

Permalink
Fleet apache: convert status.total_kbytes to status.total_bytes (#23022
Browse files Browse the repository at this point in the history
…) (#23055)

* Fleet apache: convert status.total_kbytes to status.total_bytes

* Update CHANGELOG

(cherry picked from commit 13ae2e8)
  • Loading branch information
mtojek committed Dec 10, 2020
1 parent 1872cb8 commit 2f1f269
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Adjust the Apache status fields in the fleet mode. {pull}22821[22821]
- Add AWS Fargate overview dashboard. {pull}22941[22941]
- 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*

Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/apache/status/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions metricbeat/module/apache/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions metricbeat/module/apache/status/status_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{} {
Expand Down

0 comments on commit 2f1f269

Please sign in to comment.