2014-10-19 56 views
0

如何使用FluentD在事件记录中创建值数组?FluentD中的值列表

我已经从日志中分析了经度和纬度。如何将这些值转换为数组?

Ex。 我有一个日志像

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

我已经解析纬度= -37.0081和经度= 174.792。 如何形成这样的JSON对象?

{location:[-37.0081,174.792]}

以及如何解析事件记录的字符串值数据类型?像整数/浮点数/双精度值

回答

0

创建的数组类型参数为in_tail插件。

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

但数组元素是字符串类型。

0

试试下面的配置

<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> 

然后,2014-9-23T09:27:28.345 1411464370345 -37.0081,174.792 BBC SEARCH be03debe-b0af-4939-9abc-7c0ad25bb114 DEPARTURE 16 576.00 ROLLBACK,你应该看到在标准输出下面的输出

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"} 

我Fluentd v0.10.51测试这一点,但它应该与所有工作最近的版本。