gpt4 book ai didi

logstash - 如何用日志时间戳替换logstash @timestamp

转载 作者:行者123 更新时间:2023-12-02 20:11:44 25 4
gpt4 key购买 nike

我在日志中的时间戳格式如下

2016-04-07 18:11:38.169  which is  yyyy-MM-dd HH:mm:ss.SSS

此日志文件不是实时日志文件(存储的/旧的),我正在尝试用logstash @timestamp 值替换此时间戳,以改善 Kibana 可视化效果。

我在logstash中的过滤器如下所示

     grok {
match => {
"message" => [ "(?<timestamp>(\d){4}-(\d){2}-(\d){2} (\d){2}:(\d){2}:(\d){2}.(\d){3}) %{SYSLOG5424SD} ERROR u%{BASE16FLOAT}.%{JAVACLASS} - TransId:2b948ed5-12c0-4ae0-9b99-f1ee01191001 - TransactionId ::\"2b948ed5-12c0-4ae0-9b99-f1ee01191001\"- Actual Time taken to process \:\: %{NUMBER:responseTime:int}" ]
}

}

date {
match => [ "timestamp:date" , "yyyy-MM-dd HH:mm:ss.SSS Z" ]
timezone => "UTC"
target => "@timestamp"
}

但是,它不会替换 @timestamp 值、Json 值

{
"_index": "logstash-2017.02.09",
"_type": "logs",
"_id": "AVoiZq2ITxwgj2avgkZa",
"_score": null,
"_source": {
"path": "D:\\SoftsandTools\\Kibana\\Logs_ActualTimetakentoprocess.log",
"@timestamp": "2017-02-09T10:23:58.778Z", **logstash @timestamp**
"responseTime": 43,
"@version": "1",
"host": "4637",
"message": "2016-04-07 18:07:01.809 [SimpleAsyncTaskExecutor-3] ERROR s.v.wsclient.RestClient - TransId:2b948ed5-12c0-4ae0-9b99-f1ee01191001 - TransactionId ::\"2b948ed5-12c0-4ae0-9b99-f1ee01191001\"- Actual Time taken to process :: 43",
"timestamp": "2016-04-07 18:07:01.809" **Mine time stamp**
}

日志行示例 -

2016-04-07 18:11:38.171 [SimpleAsyncTaskExecutor-1] ERROR s.v.wsclient.RestClient - TransId:2b948ed5-12c0-4ae0-9b99-f1ee01191001 - TransactionId ::"2b948ed5-12c0-4ae0-9b99-f1ee01191001"- Actual Time taken to process :: 521

你能帮忙告诉我,我要去哪里吗?

最佳答案

您基本上应该有一个 grok 匹配才能使用日志行的时间戳:

grok {
patterns_dir => ["give your path/patterns"]
match => { "message" => "^%{LOGTIMESTAMP:logtimestamp}%{GREEDYDATA}" }
}

在您的模式文件中,确保具有与日志中的时间戳匹配的模式,它可能如下所示:

LOGTIMESTAMP %{YEAR}%{MONTHNUM}%{MONTHDAY} %{TIME}

然后,一旦完成 grok 过滤,您就可以使用过滤后的值,例如:

mutate {
add_field => { "newtimestamp" => "%{logtimestamp}" }
remove_field => ["logtimestamp"]
}
date {
match => [ "newtimestamp" , "ISO8601" , "yyyy-MM-dd HH:mm:ss.SSS" ]
target => "@timestamp" <-- the timestamp which you wanted to apply on
locale => "en"
timezone => "UTC"
}

希望这有帮助!

关于logstash - 如何用日志时间戳替换logstash @timestamp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42134163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com