我需要帮助了解如何使用包含日期和时间的另一个字段的内容来设置@时间戳字段,该字段的精度为纳秒。我尝试过使用日期匹配,但我不清楚在范围中必须使用哪种模式:
date {
match => ["timestamp_nano", "ISO8601"]
target => "@timestamp"
}
其中timestamp_nano是具有纳秒精度的时间戳(例如,"2022-01-20T12:00:00.123456789Z"). )
通过使用ISO8601,可以获得毫秒的精度,而在@时间戳字段中没有报告其余的数字。
在比赛中使用哪一种模式?
提前感谢
发布于 2022-01-20 15:08:03
这个答案是8.0.0-rc1,因为8.0还没有发布。数据过滤器仍在使用Joda库,该库仅限于毫秒精度。引入纳秒精度的按下修复了底层的LogStash时间戳类,使其能够使用纳秒精度,而不是所有使用它的类。
如果我跑了
input { generator { count => 1 lines => [ '' ] } }
output { stdout { codec => rubydebug { metadata => false } } }
然后我得到了“时间戳”的微秒精度。
"@timestamp" => 2022-01-22T01:14:15.881459Z,
然而,时间戳可能比这更精确。如果我使用json编解码器
input { generator { count => 1 lines => [ '{ "@timestamp": "2022-01-10T12:13:14.123456789"}' ] codec => json } }
output { stdout { codec => rubydebug { metadata => false } } }
我有纳秒精度
"@timestamp" => 2022-01-10T17:13:14.123456789Z,
如果要使用另一个字段的值,可以执行以下操作
input { generator { count => 1 lines => [ '' ] } }
filter {
mutate { add_field => { "foo" => "2022-01-10T12:13:14.123456789" } }
mutate { add_field => { "bar" => '{ "@timestamp": "%{foo}" } ' } }
json { source => "bar" }
}
发布于 2022-08-11 11:02:24
@獾在上面给出了很好的答案,但我更喜欢在Logstash8.x中使用Ruby的一个步骤
input { generator { count => 1 lines => [ '' ] } }
filter {
mutate { add_field => { "[@timestamp_nanoseconds]" => "2022-08-11T10:10:10.123456789Z" } }
ruby {
code => "event.set('[@timestamp]', LogStash::Timestamp.new(event.get('[@timestamp_nanoseconds]')) )"
}
}
output { stdout {} }
我得到本机@时间戳(以纳秒计)
"@timestamp" => 2022-08-11T10:10:10.123456789Z,
发布于 2022-01-21 16:33:41
通过在Elasticsearch中添加一个管道,我得到了同样的结果:
{
"description": "mypipeline",
"processors": [
{
"date": {
"field": "timestamp_nano",
"formats": ["ISO8601"],
"output_format": "yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSSZ"
}
}
]
}
timestamp_nano包含一个具有纳秒精度的时间戳。
在LogT中,可以使用指示为这里的红宝石脚本来更新@时间戳,但是作者说脚本不能被优化。
BRs
https://stackoverflow.com/questions/70783837
复制相似问题