Percentage Calculation in Ruby

I am doing calculation in Ruby but the fields are empty in Kibana.

The ruby code:

                  event.set('BusinessTimeUnavailabilityinSeconds', ((event.get('BusinessUnavailabilityHours').to_i * 3600 ) + (event.get('BusinessUnavailabilityMinutes').to_i * 60) + event.get('BusinessUnavailabilitySeconds').to_i))
                  event.set('NonPrimeTimeUnavailabilityinSeconds', (event.get('TotalTimeUnavailabilityinSeconds') - event.get('BusinessTimeUnavailabilityinSeconds')))
                  event.set('BusinessTimeUnavailabilityPercentage' , (event.get('BusinessTimeUnavailabilityinSeconds').to_f).div(197100))
                  event.set('NonPrimeTimeUnavailabilityPercentage' , (event.get('NonPrimeTimeUnavailabilityinSeconds').to_f).div(118260))

After, I am converting:

mutate {
                      convert => { "NonPrimeTimeUnavailabilityinSeconds" => "integer"
                                   "TotalTimeUnavailabilityinSeconds" => "integer"
                                   "BusinessTimeUnavailabilityinSeconds" => "integer"
                                   "BusinessTimeUnavailabilityPercentage" => "float"
                                   "NonPrimeTimeUnavailabilityPercentage" => "float"
                      }                      
              }

The result in Kibana:

|#  BusinessTimeUnavailabilityPercentage|       |0|
|---|---|---|
|#  BusinessTimeUnavailabilityinSeconds|       |15,300|

As as, I would expect to get : 0.7762

What am I missing here?

Regards,
Sharon.

Float does not have a div method, it comes from Numeric, where it is defined as returning an integer. Use

100 * event.get('NonPrimeTimeUnavailabilityinSeconds').to_f / 118260

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.