Skip to content

Commit 13ae2e8

Browse files
authored
Fleet apache: convert status.total_kbytes to status.total_bytes (#23022)
* Fleet apache: convert status.total_kbytes to status.total_bytes * Update CHANGELOG
1 parent 769762b commit 13ae2e8

4 files changed

Lines changed: 18 additions & 3 deletions

File tree

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
878878
- Adjust the Apache status fields in the fleet mode. {pull}22821[22821]
879879
- Add AWS Fargate overview dashboard. {pull}22941[22941]
880880
- Add process.state, process.cpu.pct, process.cpu.start_time and process.memory.pct. {pull}22845[22845]
881+
- Apache: convert status.total_kbytes to status.total_bytes in fleet mode. {pull}23022[23022]
881882

882883
*Packetbeat*
883884

metricbeat/module/apache/status/data.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func eventMapping(scanner *bufio.Scanner, hostname string) (common.MapStr, error
129129
for scanner.Scan() {
130130
if match := matchNumber.FindStringSubmatch(scanner.Text()); len(match) == 3 {
131131
// Total Accesses: 16147
132-
//Total kBytes: 12988
132+
// Total kBytes: 12988
133133
// Uptime: 3229728
134134
// CPULoad: .000408393
135135
// CPUUser: 0

metricbeat/module/apache/status/status.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ func adjustFleetEvent(event mb.Event) mb.Event {
109109
var adjusted mb.Event
110110
adjusted.MetricSetFields = event.MetricSetFields.Clone()
111111

112+
// Convert apache.status.total_kbytes to apache.status.total_bytes
113+
totalKBytes, err := adjusted.MetricSetFields.GetValue("total_kbytes")
114+
if err == nil {
115+
adjusted.MetricSetFields.Put("total_bytes", totalKBytes.(int64)*1024)
116+
adjusted.MetricSetFields.Delete("total_kbytes")
117+
}
118+
112119
// Remove apache.hostname
113120
adjusted.MetricSetFields.Delete("hostname")
114121
return adjusted

metricbeat/module/apache/status/status_integration_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,15 @@ func TestFetchFleetMode(t *testing.T) {
6868
t.Fatal("Too few top-level elements in the event")
6969
}
7070

71-
_, err := event.MetricSetFields.GetValue("hostname")
72-
assert.Equal(t, common.ErrKeyNotFound, err, "apache.hostname shouldn't be present in the fleet mode")
71+
_, err := event.MetricSetFields.GetValue("total_kbytes")
72+
assert.Equal(t, common.ErrKeyNotFound, err, "apache.status.total_kbytes shouldn't be present in the fleet mode")
73+
74+
totalBytes, err := event.MetricSetFields.GetValue("total_bytes")
75+
assert.NoError(t, err, "apache.status.total_bytes should be present in the fleet mode")
76+
assert.GreaterOrEqual(t, totalBytes.(int64), int64(0), "apache.status.total_bytes should be non-negative")
77+
78+
_, err = event.MetricSetFields.GetValue("hostname")
79+
assert.Equal(t, common.ErrKeyNotFound, err, "apache.status.hostname shouldn't be present in the fleet mode")
7380
}
7481

7582
func getConfig(host string) map[string]interface{} {

0 commit comments

Comments
 (0)