gpt4 book ai didi

linux - Logstash 过早创建目录

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:19:21 26 4
gpt4 key购买 nike

我让我的 logstash 实例每天创建一个新目录来存储它的日志。配置文件如下。似乎在一天前的晚上创建了一个目录(并开始使用它);而不是在午夜后立即创建它(当日期实际更改时)。我在西海岸 (UTC−08:00)。我在 OEL 操作系统上。

配置:

input {
udp {
port => 6379
}
}

filter {
ruby {
code => "event['@timestamp'] = event['@timestamp'].localtime('-08:00')"
}
}

output {
file {
path => ["/logstash-1.4.1/logs/%{+YYYY-MM-dd}/logstash_in.txt"]
}
elasticsearch {
protocol => http
}
stdout {
codec => rubydebug
}
}

我的系统日期和时间是正确的:

[root@xxx]# date
Mon Jul 14 18:22:37 PDT 2014

最佳答案

简答,文件输出路径时间戳%{+YYYY-MM-dd}是指UTC时间。这意味着您的目录将在您晚上创建。

长答案可以引用file output source code .路径是

path = event.sprintf(@path)

并深入到 event.rb

t = @data["@timestamp"]
formatter = org.joda.time.format.DateTimeFormat.forPattern(key[1 .. -1])\
.withZone(org.joda.time.DateTimeZone::UTC)
#next org.joda.time.Instant.new(t.tv_sec * 1000 + t.tv_usec / 1000).toDateTime.toString(formatter)
# Invoke a specific Instant constructor to avoid this warning in JRuby
# > ambiguous Java methods found, using org.joda.time.Instant(long)
org.joda.time.Instant.java_class.constructor(Java::long).new_instance(
t.tv_sec * 1000 + t.tv_usec / 1000
).to_java.toDateTime.toString(formatter)

路径参数 %{+YYYY-MM-dd} 基于 UTC 时间:(org.joda.time.DateTimeZone::UTC).

所以,有两种解决方案可以满足您的需求,

a) 修改 event.rb 以使用您的时区,而不是 UTC。

b) 创建一个您自己的日期字段并使用您指定的字段 %{+YYYY-MM-dd}这是我的配置:

filter {
ruby {
code => "
ownTime = event['@timestamp'].localtime('-08:00')
event['day'] = ownTime.strftime('%Y-%m-%d')
"
}
}

output {
file {
path => "/logstash-1.4.1/logs/%{day}/logstash_in.txt"
}
stdout {
codec => "rubydebug"
}
}

希望对您有所帮助。

关于linux - Logstash 过早创建目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24748601/

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