试图在logstash中执行下面的代码,但是它一直抛出一个异常。
if [received_at] and [sent_at] {
ruby {
init => "require 'time'"
code => "
received_by_finacle = (Time.parse(event.get('received_at').to_f)*1000).round(2);
sent_out_by_finacle = (Time.parse(event.get('sent_at').to_f)*1000).round(2);
event.set('delta', (sent_out_by_finacle - received_by_finacle)).to_s;
event.set('epoch_received_at_in_milliseconds', received_by_finacle);
event.set('epoch_sent_at_in_milliseconds', sent_out_by_finacle);
"
add_tag => [ "calculated_time_difference" ]
}
} 返回的错误是
[2018-10-10T22:01:05,631][ERROR][logstash.filters.ruby ] Ruby exception occurred: allocator undefined for Float
[2018-10-10T22:01:05,640][ERROR][logstash.filters.ruby ] Ruby exception occurred: allocator undefined for Float有什么好主意吗?
发布于 2018-10-11 23:14:17
多亏了一个logstash社区成员@Ganesh_Venkataraman,我才能找到解决方案。我不得不加上一个“救援零”(稍后会读到更多)。这是最后对我有用的代码。
if [received_at] and [sent_at] {
ruby {
init => "require 'time'"
code => "
received_by_finacle = (Time.parse(event.get('received_at')).to_f)*1000;
sent_out_by_finacle = (Time.parse(event.get('sent_at')).to_f)*1000;
timetaken = (sent_out_by_finacle - received_by_finacle) rescue nil;
event.set('time_delta',timetaken);
event.set('epoch_received_at_in_milliseconds',received_by_finacle);
event.set('epoch_sent_at_in_milliseconds',sent_out_by_finacle);
"
add_tag => [ "calculated_time_difference" ]
}
} 谢谢。
https://stackoverflow.com/questions/52748956
复制相似问题