首页 文章

从日志文件中抽出时间

提问于
浏览
0

以下是原始日志:

2017-09-17 08:34:54 181409 10.110.82.122 200 TCP_TUNNELED 4440 1320 CONNECT tcp cdn.appdynamics.com 443 / - ANILADE - 10.100.134.6 - - “Mozilla / 5.0(Windows NT 10.0; Win64; x64)AppleWebKit / 537.36(KHTML,与Gecko一样)Chrome / 60.0.3112.113 Safari / 537.36“OBSERVED”Technology / Internet“ - 10.100.134.6

这是我的logstash配置文件:

input {
    beats {
        port => "5044"
    }
}

filter 
#start of filter
{
grok 
#start of grok filter
{
match =>
#start of match
{"message"=>"%{TIMESTAMP_ISO8601:@timestamp} (%{NUMBER:time_taken}|\-) (%{IP:sourceIP}|\-) (%{NUMBER:status}|\-) (%{WORD:action}|\-) (%{NUMBER:scBytes}|\-) (%{NUMBER:csBytes}|\-) (%{WORD:method}|\-) (%{WORD:uri_scheme}|\-) (%{URIHOST:url}|\-) (%{NUMBER:port}|\-) (?<uri_path>([a-zA-Z0-9\/\.\?\-\_]+)|(\/)) (?<uri_query>([a-zA-Z0-9\/\.\?\-\=\&\%]+)) (?<username>([a-zA-Z0-9\/\.\?\-]+)) (?<auth_group>([a-zA-Z0-9\/\.\?\-]+)) (?<destIP>([a-zA-Z0-9\.\-]+)) (?<content_type>([a-zA-Z0-9\-\/\;\%\=]+)) (?<referer>[a-zA-Z0-9\-\/\;\%\=\:\.]+) (%{QUOTEDSTRING:user_agent}|\-) (%{WORD:filter_result}|\-) (%{QUOTEDSTRING:category}|\-) (?<vir_id>([a-zA-Z0-9\-\/.])) (%{IP:proxyIP}|\-)"
}
#end of match
}
#end of grok
date
#start of date filter
{
match=>["@timestamp","ISO8601"]
}
#end of date filter
}
#end of filter


output 
{

    elasticsearch 
    {
    hosts => ["localhost:9200"] 
    index => proxylog
    }
}

我想从日志中选择时间,因此我按照Date Plugin文档中的建议使用了日期过滤器 . 但无论配置如何,当我在Kibana中查看时,我可以看到logstash elasticsearch在@timestamp字段中显示索引时间 . 我找不到我错过的或错在哪里 . 我试着用替换它来在grok过滤器中使用TIMESTAMP_ISO8601

%{YEAR:year}-%{MONTHNUM:month}-%{MONTHDAY:day} %{TIME:time}

并添加字段时间戳为:

add_field=>["timestamp","%{year}-%{month}-%{day} %{time}"]

然后将日期过滤器配置更改为

date{
match=>["timestamp","YYYY-MM-DD HH:mm:ss"]
remove_field=>["timestamp","year","month","day"]}
}

并没有找到运气 . 有人可以指出一个解决方案,因为在elasticsearch和stackoverflow论坛上发现的任何链都没有帮助 . 任何人都可以告诉我是否需要更改filebeat的任何配置,因为我使用filebeat将日志发送到logstash .

2 回答

  • 1

    您可以在日期过滤器中添加 target => "new_field" 并使用它在Kibana中创建索引

  • 0

    可能是因为 @timestamp 是一个时间戳字段,但你的grok {}正在将它视为一个字符串 .

    首先,将字符串转换为新字段,例如

    %{TIMESTAMP_ISO8601:[@metadata][timestamp]}
    

    然后使用带有[@metadata] [timestamp]的date {}过滤器作为输入来设置@timestamp .

相关问题