diff --git a/metricbeat/docs/fields.asciidoc b/metricbeat/docs/fields.asciidoc index 608a4013abdc..6d51fcc7a0a0 100644 --- a/metricbeat/docs/fields.asciidoc +++ b/metricbeat/docs/fields.asciidoc @@ -4117,6 +4117,16 @@ type: keyword The HTTP status code +[float] +=== `http.response.phrase` + +type: keyword + +example: Not found + +The HTTP status phrase + + [float] === `http.response.body` diff --git a/metricbeat/module/http/_meta/fields.yml b/metricbeat/module/http/_meta/fields.yml index 5f7601685634..6a3fae885ad7 100644 --- a/metricbeat/module/http/_meta/fields.yml +++ b/metricbeat/module/http/_meta/fields.yml @@ -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: > diff --git a/metricbeat/module/http/_meta/test/main.go b/metricbeat/module/http/_meta/test/main.go index a2a7cad313aa..9dc520f6e1a7 100644 --- a/metricbeat/module/http/_meta/test/main.go +++ b/metricbeat/module/http/_meta/test/main.go @@ -15,5 +15,5 @@ func main() { } func serve(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, `{"hello":"world"}`) + fmt.Fprint(w, `{"hello":"world"}`) } diff --git a/metricbeat/module/http/json/json.go b/metricbeat/module/http/json/json.go index 5b914c2d4345..95f23f14bb30 100644 --- a/metricbeat/module/http/json/json.go +++ b/metricbeat/module/http/json/json.go @@ -4,6 +4,7 @@ import ( "encoding/json" "io/ioutil" "net/http" + "strconv" "strings" "github.com/elastic/beats/libbeat/common" @@ -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), }, }