Class: PunyMonitor::Scheduler

Inherits:
Object
  • Object
show all
Defined in:
app/scheduler.rb

Class Method Summary collapse

Class Method Details

.cleanup_old_dataObject



25
26
27
28
29
30
# File 'app/scheduler.rb', line 25

def cleanup_old_data
  one_month_ago = 1.month.ago
  [CpuUsage, CpuLoad, MemoryUsage, FilesystemUsage, DiskIO, Bandwidth].each do |model|
    model.where("created_at < ?", one_month_ago).delete_all
  end
end

.collect_dataObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/scheduler.rb', line 9

def collect_data
  CpuUsage.create(used_percent: SystemUtils.cpu_usage_percent)
  cpu_load_averages = SystemUtils.cpu_load_average
  CpuLoad.create(one_minute: cpu_load_averages[0],
                 five_minutes: cpu_load_averages[1],
                 fifteen_minutes: cpu_load_averages[2])
  MemoryUsage.create(used_percent: SystemUtils.memory_usage_percent)
  FilesystemUsage.create(used_percent: SystemUtils.filesystem_usage_percent)

  disk_io = SystemUtils.disk_io_stats
  DiskIO.create(read_mb_per_sec: disk_io[:read_mb_per_sec], write_mb_per_sec: disk_io[:write_mb_per_sec])

  bandwidth = SystemUtils.bandwidth_usage
  Bandwidth.create(incoming_mbps: bandwidth[:incoming_mbps], outgoing_mbps: bandwidth[:outgoing_mbps])
end