Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Date 日志存储日期匹配不更新@时间戳_Date_Format_Logstash - Fatal编程技术网

Date 日志存储日期匹配不更新@时间戳

Date 日志存储日期匹配不更新@时间戳,date,format,logstash,Date,Format,Logstash,日志字符串示例: 2014-06-01 00:00:48 192.168.1.1 968 http://yandex.ru 日志存储配置: input { file { path => "/home/michael/logs/squid.log" start_position => "beginning" } } filter { grok { match => [ "message", "%{YEAR:year}-%{M

日志字符串示例:

2014-06-01  00:00:48    192.168.1.1 968 http://yandex.ru
日志存储配置:

input {
    file {
    path => "/home/michael/logs/squid.log"
    start_position => "beginning"
    }
}

filter {
  grok {
    match => [ "message", "%{YEAR:year}-%{MONTHNUM:month}-%{MONTHDAY:day}\t+%{TIME:time}\t+%{IPORHOST:userID}|{WORD:userID}\t+%{NUMBER:response_size}\t+%{URIHOST:dst_host}|{URI:dst_host}" ]
  }
  mutate {
    add_field => { "timestamp" => "%{year}-%{month}-%{day} %{time}" } 
  }
  date {
    match => [ "timestamp", "yyyy-MM-dd HH:mm:ss" ]
  }
}

output {
    elasticsearch { host => localhost }
    stdout { codec => rubydebug }
}
虽然没有添加日期过滤器,但它工作得很好:日志解析和字段添加。但随着日期过滤器的出现,消息的某些部分消失了,logstash日志说:

{:timestamp=>"2014-07-26T22:48:44.413000+0600", :message=>"Failed parsing date from field", :field=>"timestamp", :value=>"%{year}-%{month}-%{day} %{time}", :exception=>java.lang.IllegalArgumentException: Invalid format: "%{year}-%{month}-%{day} %{time}", :level=>:warn}

这里发生了什么?

通过您的配置和日志,它在我的1.4.1版上运行

我认为这可能是您的grok模式解析错误,否则不会出现此错误消息
:value=>“%{year}-%{month}-%{day}%{time}”

错误消息表示您添加的
timestamp
字段的内容是
%{year}-%{month}-%{day}%{time}
。 这意味着grok筛选器解析错误

您可以做的是,检查日志是否为
空白(“”
选项卡(\t)
)。如果是空白,则不能在模式中使用
\t

更新:

您可以将
\t
更改为
[\t]
。此模式解析空格和
\t

%{YEAR:year}-%{MONTHNUM:month}-%{MONTHDAY:day}[ \t]+%{TIME:time}[ \t]+%{IPORHOST:userID}|{WORD:userID}[ \t]+%{NUMBER:response_size}[ \t]+%{URIHOST:dst_host}|{URI:dst_host}

希望这能帮助你

我查过了-标签在这里。我不明白,为什么grok在没有日期过滤器的情况下解析得很好,却失败了。我的logstash版本是1.4.2,如果有必要的话。当我使用您的配置进行测试时,我遇到了“\u grokparsefailure”错误。请检查何时发生日期分析错误,是否出现grok failure标记。我认为无论你用什么版本都是如此。从您发布的错误消息中,grok解析失败并导致时间戳值为%{year}-%%{month}-%%{day}%{time}我删除了所有索引并尝试重新启动logstash服务两次。结果是两条不同的(似乎是随机的)损坏消息(
rt.ru/www/delivery/lg.php?
:36 192.168.1.1 464http://mc.yandex.ru/clmap/13086418?
)在时间戳字段中使用
%{year}-%{month}-%{day}%{time}
\u grokparsefailure
标记。我已更新了答案。请参考grok模式。这对我起作用了,谢谢。你说得对:这是格罗克问题。我完成了
%{YEAR:YEAR}-%{MONTHNUM:month}-%{MONTHDAY:day}%{SPACE}%{TIME:TIME}%{SPACE}(%%{IPORHOST:userID}}{WORD userID})%{SPACE}%{NUMBER:response_size}%{SPACE}(%%URI URI dst_主机}{124;{URIHOST:dst_主机})
filter。