Class: CpuUsage

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/cpu_usage.rb

Class Method Summary collapse

Class Method Details

.average_usage(start_time, group_by) ⇒ Object



4
5
6
7
8
9
# File 'app/models/cpu_usage.rb', line 4

def self.average_usage(start_time, group_by)
  where(created_at: start_time..)
    .group_by_period(group_by, :created_at, expand_range: true)
    .average(:used_percent)
    .transform_values { |value| value&.round(2) }
end