From a5c9c5e8b256dfb41e8e0656f4849ca47cd204b5 Mon Sep 17 00:00:00 2001 From: kel Date: Wed, 8 Nov 2017 17:30:35 -0600 Subject: [PATCH] Add HTTP status phrase in reponse for metricsbeat http module (#5470) (#5484) --- metricbeat/docs/fields.asciidoc | 10 ++++++++++ metricbeat/module/http/_meta/fields.yml | 5 +++++ metricbeat/module/http/_meta/test/main.go | 2 +- metricbeat/module/http/json/json.go | 3 +++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/metricbeat/docs/fields.asciidoc b/metricbeat/docs/fields.asciidoc index 4d348130c224..ab11a7cb77ba 100644 --- a/metricbeat/docs/fields.asciidoc +++ b/metricbeat/docs/fields.asciidoc @@ -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` 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), }, }