Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
执行ruby代码时出现Logstash错误(发生ruby异常:未定义浮点分配器)_Ruby_Logstash - Fatal编程技术网

执行ruby代码时出现Logstash错误(发生ruby异常:未定义浮点分配器)

执行ruby代码时出现Logstash错误(发生ruby异常:未定义浮点分配器),ruby,logstash,Ruby,Logstash,试图在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.

试图在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

你知道为什么吗?

多亏了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" ]
    }
} 
谢谢