0

I am using http_poller as input and get back a json array. I'm using default json codec. The json looks like this:

[{"name":"UsedMemory","value": {"value":"222932448","type":"java.lang.Long"}}, {"name":"FreeMemory","value":{"value":"308630048","type":"java.lang.Long"}}, {"name":"Heap","value":{"value":"531562496","type":"java.lang.Long"}},{"name":"UpTime","value":{"value":"29900897","type":"java.lang.Long"}},{"name":"ProcessCPU","value":{"value":"0.15846178794662266","type":"java.lang.Double"}}, {"name":"GcCount","value":{"value":"2198","type":"java.lang.Long"}},{"name":"GcTime","value":{"value":"35658","type":"java.lang.Long"}}]

I see that logstash treats each array element as a new event by splitting up the array. Eg

{
    "name" => "UpTime",
    "value" => {
    "value" => "29579549",
    "type" => "java.lang.Long"
},
    "@version" => "1",
    "@timestamp" => "2016-11-17T04:12:45.492Z"
}
{
    "name" => "ProcessCPU",
    "value" => {
    "value" => "0.16146030555740817",
    "type" => "java.lang.Double"
},
    "@version" => "1",
    "@timestamp" => "2016-11-17T04:12:45.492Z"
}
...

How can I get logstash (2.4) to combine the elements, treat it as one event and output it like this

{
    "Uptime" => "29579549"
    "ProcessCPU" => ""0.16146030555740817"
    ....

}

I think I have to generate a new field like this but go through all the elements of the array to make one complete event. { "%{name}" => "%{[value][value]}" ... }

1 Answer 1

1

After reading a bit more about logstash and experimenting, I found the answer:

  1. In the http_poller, change the codec to "plain"
  2. In the filter section, use a json filter. eg
json {
  source => "message"
  target => "doc"
  }
  1. Add a ruby code filter to process the json doc field as follows:
ruby {
code => "
event['doc'].each { |elem|
event[ elem['name']] = elem['value']['value']}
"
}
  1. Remove doc and message fields using mutate filter
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.