Class: ProxES::MemoryStatusCheck

Inherits:
StatusCheck
  • Object
show all
Defined in:
lib/proxes/models/status_checks/memory_status_check.rb

Constant Summary

Constants inherited from StatusCheck

StatusCheck::SOURCE_CALLS

Instance Method Summary collapse

Methods inherited from StatusCheck

#passed?, #policy_class, #source_result, source_result, #validate

Methods included from Services::ES

#client, #conn, #ssl_store

Instance Method Details

#checkObject



19
20
21
22
23
# File 'lib/proxes/models/status_checks/memory_status_check.rb', line 19

def check
  return true if required_value.blank?

  value < required_value.to_f
end

#childrenObject



10
11
12
13
14
15
16
17
# File 'lib/proxes/models/status_checks/memory_status_check.rb', line 10

def children
  @children ||= source_result['nodes']['nodes'].values.map do |node|
    [
      node['name'],
      node['os']['mem']['used_percent'].to_f
    ]
  end.to_h
end

#formatted(val = nil) ⇒ Object



25
26
27
# File 'lib/proxes/models/status_checks/memory_status_check.rb', line 25

def formatted(val = nil)
  format('%.4f%% Average Usage', val || value)
end

#valueObject



5
6
7
8
# File 'lib/proxes/models/status_checks/memory_status_check.rb', line 5

def value
  # Currently checks the average. Can change it to check per node too
  children.values.inject(0.0) { |sum, el| sum + el } / children.count
end