0

How to create array of values in the event record with FluentD?

I have parsed latitude and longitude from the log. How to transform these values to an array ?

Ex. I have a log like

2014-9-23T09:27:28.345 1411464370345 -37.0081,174.792 BBC SEARCH be03debe-b0af-4939-9abc-7c0ad25bb114 DEPARTURE 16 576.00 ROLLBACK

I have parsed latitude=-37.0081 and longitude =174.792. How to form a JSON object like this ?

{location:[-37.0081,174.792]}

And how to parse the string value to data types in the event record ? Like integer /float / double

Ahamed Mustafa M
  • 3,069
  • 1
  • 24
  • 34

2 Answers2

0

Created array with types parameter of in_tail plugin.

types qty:integer,txamount:float,location:array

But the array elements are of string type.

Ahamed Mustafa M
  • 3,069
  • 1
  • 24
  • 34
0

Try the following configuration

<source>
  type tail
  path stackoverflow.log
  format /^(?<time>[^ ]+) (?<field_1>[^ ]+) (?<array_field>[^ ]+) (?<rest>.+)$/
  time_format %Y-%m-%dT%H:%M:%S
  types array_field:array
  tag test
</source>

<match test>
  type stdout
</match>

Then, for 2014-9-23T09:27:28.345 1411464370345 -37.0081,174.792 BBC SEARCH be03debe-b0af-4939-9abc-7c0ad25bb114 DEPARTURE 16 576.00 ROLLBACK, you should see the following output in stdout

2014-09-23 09:27:28 +0000 test: {"field_1":"1411464370345","array_field":["-37.0081","174.792"],"rest":"BBC SEARCH be03debe-b0af-4939-9abc-7c0ad25bb114 DEPARTURE 16 576.00 ROLLBACK"}

I tested this with Fluentd v0.10.51, but it should work with all recent versions.

Kiyoto Tamura
  • 700
  • 6
  • 7