Class: RorVsWild::Metrics

Inherits:
Object
  • Object
show all
Defined in:
lib/rorvswild/metrics.rb,
lib/rorvswild/metrics/cpu.rb,
lib/rorvswild/metrics/memory.rb,
lib/rorvswild/metrics/storage.rb

Defined Under Namespace

Classes: Cpu, Memory, Storage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMetrics

Returns a new instance of Metrics.



5
6
7
8
9
10
# File 'lib/rorvswild/metrics.rb', line 5

def initialize
  @updated_at = nil
  @cpu = RorVsWild::Metrics::Cpu.new
  @memory = RorVsWild::Metrics::Memory.new
  @storage = RorVsWild::Metrics::Storage.new
end

Instance Attribute Details

#cpuObject (readonly)

Returns the value of attribute cpu.



3
4
5
# File 'lib/rorvswild/metrics.rb', line 3

def cpu
  @cpu
end

#memoryObject (readonly)

Returns the value of attribute memory.



3
4
5
# File 'lib/rorvswild/metrics.rb', line 3

def memory
  @memory
end

#storageObject (readonly)

Returns the value of attribute storage.



3
4
5
# File 'lib/rorvswild/metrics.rb', line 3

def storage
  @storage
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



3
4
5
# File 'lib/rorvswild/metrics.rb', line 3

def updated_at
  @updated_at
end

Instance Method Details

#to_hObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rorvswild/metrics.rb', line 26

def to_h
  {
    hostname: Host.name,
    os: Host.os,
    cpu_user: cpu.user,
    cpu_system: cpu.system,
    cpu_idle: cpu.idle,
    cpu_waiting: cpu.waiting,
    cpu_stolen: cpu.stolen,
    cpu_count: cpu.count,
    load_average: cpu.load_average,
    ram_total: memory.ram_total,
    ram_free: memory.ram_free,
    ram_used: memory.ram_used,
    ram_cached: memory.ram_cached,
    swap_total: memory.swap_total,
    swap_used: memory.swap_used,
    swap_free: memory.swap_free,
    storage_total: storage.total,
    storage_used: storage.used,
    storage_free: storage.free,
  }
end

#updateObject



12
13
14
15
16
# File 'lib/rorvswild/metrics.rb', line 12

def update
  cpu.update
  memory.update
  storage.update
end

#update_every_minuteObject



18
19
20
21
22
23
24
# File 'lib/rorvswild/metrics.rb', line 18

def update_every_minute
  return unless Host.os.include?("Linux")
  if !@updated_at || @updated_at.min != Time.now.min
    @updated_at = Time.now
    update
  end
end