Skip to content

Commit

Permalink
Add HTTP status phrase in reponse for metricsbeat http module (#5470) (
Browse files Browse the repository at this point in the history
  • Loading branch information
kel authored and ruflin committed Nov 8, 2017
1 parent 3eb68bf commit a5c9c5e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -4442,6 +4442,16 @@ type: keyword
The HTTP status code
[float]
=== `http.response.phrase`
type: keyword
example: Not found
The HTTP status phrase
[float]
=== `http.response.body`
Expand Down
5 changes: 5 additions & 0 deletions metricbeat/module/http/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
type: keyword
description: >
The HTTP status code
- name: phrase
type: keyword
example: Not found
description: >
The HTTP status phrase
- name: body
type: keyword
description: >
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/http/_meta/test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ func main() {
}

func serve(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `{"hello":"world"}`)
fmt.Fprint(w, `{"hello":"world"}`)
}
3 changes: 3 additions & 0 deletions metricbeat/module/http/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"io/ioutil"
"net/http"
"strconv"
"strings"

"github.com/elastic/beats/libbeat/common"
Expand Down Expand Up @@ -124,9 +125,11 @@ func (m *MetricSet) Fetch() (common.MapStr, error) {
}

if m.responseEnabled {
phrase := strings.TrimPrefix(response.Status, strconv.Itoa(response.StatusCode)+" ")
event[mb.ModuleDataKey] = common.MapStr{
"response": common.MapStr{
"status_code": response.StatusCode,
"phrase": phrase,
"headers": m.getHeaders(response.Header),
},
}
Expand Down

0 comments on commit a5c9c5e

Please sign in to comment.