【发布时间】:2023-03-30 15:10:01
【问题描述】:
在我的场景中,Logstash 接收的系统日志行的“时间戳”是 UTC,我们在 Elasticsearch 输出中使用事件“时间戳”:
output {
elasticsearch {
embedded => false
host => localhost
port => 9200
protocol => http
cluster => 'elasticsearch'
index => "syslog-%{+YYYY.MM.dd}"
}
}
我的问题是,在 UTC 午夜,Logstash 在一天结束之前在时区(GMT-4 => America/Montreal)将日志发送到不同的索引,并且索引在 20 小时(晚上 8 点)之后没有日志,因为“时间戳”是 UTC。
我们已经完成了转换时区的工作,但我们遇到了显着的性能下降:
filter {
mutate {
add_field => {
# Create a new field with string value of the UTC event date
"timestamp_zoned" => "%{@timestamp}"
}
}
date {
# Parse UTC string value and convert it to my timezone into a new field
match => [ "timestamp_zoned", "yyyy-MM-dd HH:mm:ss Z" ]
timezone => "America/Montreal"
locale => "en"
remove_field => [ "timestamp_zoned" ]
target => "timestamp_zoned_obj"
}
ruby {
# Output the zoned date to a new field
code => "event['index_day'] = event['timestamp_zoned_obj'].strftime('%Y.%m.%d')"
remove_field => [ "timestamp_zoned_obj" ]
}
}
output {
elasticsearch {
embedded => false
host => localhost
port => 9200
protocol => http
cluster => 'elasticsearch'
# Use of the string value
index => "syslog-%{index_day}"
}
}
有没有办法优化这个配置?
【问题讨论】:
-
@timestamp字段应该是 UTC。其他工具(如 Kibana 和 Elasticsearch Curator)依赖于此,除非您有充分的理由,否则不应更改它。
标签: ruby indexing elasticsearch timezone logstash