Skip to content

Instantly share code, notes, and snippets.

@imweijh
Last active February 10, 2021 07:43
Show Gist options
  • Save imweijh/f544c616b3cae2cd681bde18cd69b8ec to your computer and use it in GitHub Desktop.
Save imweijh/f544c616b3cae2cd681bde18cd69b8ec to your computer and use it in GitHub Desktop.
logstash timestamp test
input {
generator {
message => "2020-02-10T15:14:15.003Z"
count => 1
}
}
filter {
ruby {
code => "
event.set('s_time', Time.now)
# sleep(1)
# event.set('e_time', Time.now)
"
}
mutate {
add_field => { "timestamp_logstash_add_field" => "%{@timestamp}" }
}
ruby {
code => "event.set('timestamp_logstash_ruby',event.get('@timestamp'))"
}
grok {
match => { "message" => "%{TIMESTAMP_ISO8601:timestamp_source}" }
}
date {
match => [ "timestamp_source", "ISO8601" ]
}
ruby {
code => "event.set('time_elapsed_ruby',event.get('timestamp_logstash_ruby') - event.get('@timestamp'))"
}
}
output { stdout { codec => rubydebug } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment