Skip to content

Instantly share code, notes, and snippets.

@imweijh
Last active November 6, 2023 07:44
Show Gist options
  • Save imweijh/cf7038b21c096a6fddd98229fce30679 to your computer and use it in GitHub Desktop.
Save imweijh/cf7038b21c096a6fddd98229fce30679 to your computer and use it in GitHub Desktop.
logstash配置,在某个时间段,加tags,比如只在此时间段内才记录全量日志
input {
generator {
lines => [
"line 1",
"line a"
]
count => 1
}
}
filter {
grok { match => [ "message", "^line \d$" ] }
ruby {
init => "require 'time'"
code => "
current_time = Time.now
start_time = Time.parse('09:20')
end_time = Time.parse('09:50')
if current_time >= start_time && current_time <= end_time
event.tag('logall')
else
event.tag('lognotall')
end
"
}
}
output { stdout { codec => rubydebug } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment