Logstash CSV无法使用

时间:2014-04-23 13:42:55

标签: csv logstash

我正在尝试在logstash中读取CSV数据,但有些logstash不能将字符串分开,将它们视为csv

logstash config

input {
    file {
        path => [ "/root/logstash/temp.csv" ]
        start_position => "beginning"
    }
}
filter {
    csv {
        columns => ['A','B','C','D','E']
    }
}

output {
    stdout { }
}

测试CSV文件

p,q,r,s,t

p,q,r,s,t

p,q,r,s,t

p,q,r,s,t

p,q,r,s,t

p,q,r,s,t

输入logstash

2014-04-23T13:26:53.415+0000 0.0.0.0 p,q,r,s,t

2014-04-23T13:26:53.416+0000 0.0.0.0 p,q,r,s,t

2014-04-23T13:26:53.416+0000 0.0.0.0 p,q,r,s,t

2014-04-23T13:26:53.417+0000 0.0.0.0 p,q,r,s,t

2014-04-23T13:26:53.417+0000 0.0.0.0 p,q,r,s,t

2014-04-23T13:26:53.418+0000 0.0.0.0 p,q,r,s,t

有人可以帮我解决这个问题吗?

1)我尝试用列中的双引号替换单引号

2)我尝试了不同的数据

我期待此链接https://blog.trifork.com/2014/01/28/using-logstash-elasticsearch-and-kibana-to-monitor-your-video-card-a-tutorial/

中提到的列式输出

1 个答案:

答案 0 :(得分:8)

在输出中,您需要指定编解码器。

例如,使用configuraiton,

input {
   file {
       path => [ "/root/logstash/temp.csv" ]
       start_position => "beginning"
   }
}
filter {
    csv {
        columns => ['A','B','C','D','E']
    }
}

output {
    stdout { 
        codec => rubydebug
    }
}

添加编解码器,然后您就可以获得所需内容。

{
   "message" => [
    [0] "p,q,r,s,t"
],
  "@version" => "1",
"@timestamp" => "2014-04-24T02:57:37.099Z",
         "A" => "p",
         "B" => "q",
         "C" => "r",
         "D" => "s",
         "E" => "t"
}