Class: CpuLoad

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

Class Method Summary collapse

Class Method Details

.average_for_period(column, start_time, end_time, group_by) ⇒ Object



12
13
14
15
16
17
# File 'app/models/cpu_load.rb', line 12

def self.average_for_period(column, start_time, end_time, group_by)
  where(created_at: start_time..end_time)
    .group_by_period(group_by, :created_at)
    .average(column)
    .transform_values { |value| value&.round(2) }
end

.average_load(start_time, end_time, group_by) ⇒ Object



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

def self.average_load(start_time, end_time, group_by)
  [
    { name: "1 minute", data: average_for_period(:one_minute, start_time, end_time, group_by) },
    { name: "5 minutes", data: average_for_period(:five_minutes, start_time, end_time, group_by) },
    { name: "15 minutes", data: average_for_period(:fifteen_minutes, start_time, end_time, group_by) }
  ]
end