Logstash:UNIX Epoch时间没有转换为可读格式

我已经build立了一个ELK堆栈,我正在尝试parsing鱿鱼日志条目。

我有一个问题试图将下面的UNIX / Epoc时间转换为

1442469455.757 

以可读的格式。

在解决问题时,出现以下错误:

收到一个事件,该事件的字符编码与您configuration的不同。

而且这个标签带有"_dateparsefailure"标签,意味着它失败了。

我已经使用了下面的logstashfilter

 filter { if [type] == "squid" { grok { patterns_dir => [ "/etc/logstash/patterns" ] match => { message => "%{SQUID_LOG}" } } date { match => [ "timestamp", "UNIX" ] } } } 

定义为与主要模式"%{SQUID_LOG}"中的时间戳匹配的正则expression式模式是: (%{DATA:timestamp})

请让我知道是否有永久的解决scheme或解决方法。

提前致谢。

更新:

这似乎是由时间戳之后的额外空间引起的,如下所述:

 value=>"1438744871.647\\xA0\\xA0\\xA0\\xA0\\xA0", :exception=>"Invalid UNIX epoch value '1438744871.647\\xA0\\xA0\\xA0\\xA0\\xA0'", :config_parsers=>"UNIX", :config_locale=>"default=en_GB", :level=>:warn 

有没有办法摆脱时间戳后的'\\xA0\\xA0\\xA0\\xA0\\xA0'

configuration:

 input { stdin { } } filter { grok { match => { message => "((%{DATA:time_stamp}) (%{NUMBER:time_elapsed_ms}) (%{IPV4:client_ip}) (%{WORD:req_stat})/(%{INT:reply_code}) (%{INT:request_size}) (%{WORD:http_method}) (%{URIPROTO:request_protocol}://)?%{IPORHOST:request_hostname}(?::%{POSINT:port})?(?:%{URIPATHPARAM:uri_param}|) (%{USERNAME:user}) (%{WORD:squid_hierarchy})/(%{HOST:server}|-) (%{DATA:content_type}) (%{WORD:snaction}|-))" } add_tag => "NONU" } mutate { strip => [ "time_stamp" ] } date { match => [ "time_stamp", "UNIX" ] } } output { stdout { codec => rubydebug } } 

样本数据:

 1442469456.136     1 19.108.217.100 DENIED/407 3864 CONNECT fei.wsp.microsoft.com:443 - HIER_NONE/- text/html - 

如果错误确实是由time_stamp字段中的多余空白引起的,则可以使用mutate筛选器将其去掉。 你的filter会看起来像这样:

 filter { if [type] == "squid" { grok { patterns_dir => [ "/etc/logstash/patterns" ] match => { message => "%{SQUID_LOG}" } } mutate { strip => ["time_stamp"] } date { match => [ "time_stamp", "UNIX" ] } } } 

更新

如果所有日志条目在时间戳后都有6个额外的空格,请按照以下方式更新您的grok模式。 请注意time_stamptime_epapsed_ms之间的多余空格。

 ((%{DATA:time_stamp}) (%{NUMBER:time_elapsed_ms}) (%{IPV4:client_ip}) (%{WORD:req_stat})/(%{INT:reply_code}) (%{INT:request_size}) (%{WORD:http_method}) (%{URIPROTO:request_protocol}://)?%{IPORHOST:request_hostname}(?::%{POSINT:port})?(?:%{URIPATHPARAM:uri_param}|) (%{USERNAME:user}) (%{WORD:squid_hierarchy})/(%{HOST:server}|-) (%{DATA:content_type}) (%{WORD:snaction}|-)) 

如果有可能多于或less于6个空格,下面应该工作。

 ((%{DATA:time_stamp})%{SPACE}(%{NUMBER:time_elapsed_ms}) (%{IPV4:client_ip}) (%{WORD:req_stat})/(%{INT:reply_code}) (%{INT:request_size}) (%{WORD:http_method}) (%{URIPROTO:request_protocol}://)?%{IPORHOST:request_hostname}(?::%{POSINT:port})?(?:%{URIPATHPARAM:uri_param}|) (%{USERNAME:user}) (%{WORD:squid_hierarchy})/(%{HOST:server}|-) (%{DATA:content_type}) (%{WORD:snaction}|-)) 

我怀疑这是SQUID_LOG的parsing(像一个令牌丢失或放错位置)。

你可以看到更多,如果你把你的过滤代码之间:

 input { file { path => "/opt/logstash/squid.log" type => "squid" start_position => "beginning" sincedb_path => "/dev/null" } } [filter] output { stdout { codec => rubydebug } } 

其中/opt/logstash/squid.log只是一些有问题的日志行。

附:

 /opt/logstash/bin/logstash -f this_test_conf_file.conf 

你会在屏幕上看到它发生了什么。