Class: Malsh::HostMetrics::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/malsh/host_metrics/base.rb

Direct Known Subclasses

Cpu, Memory

Class Method Summary collapse

Class Method Details

.all_keys?(metrics) ⇒ Boolean



31
32
33
# File 'lib/malsh/host_metrics/base.rb', line 31

def all_keys?(metrics)
  resources.all? {|k| metrics.keys.include?(k) }
end

.check(hosts) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/malsh/host_metrics/base.rb', line 4

def check(hosts)
  to  = Time.now.to_i
  # 7 = 1week
  from = to - (Malsh.options[:past_date] || 7) * 86400

  if Malsh.options[option_name]
    Parallel.map(hosts) do |h|
      value = get_max_usage(h, from, to) if h
      h if value && lower?(value)
    end || []
  else
    hosts
  end
end

.get_host_metrics(host, from, to) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/malsh/host_metrics/base.rb', line 49

def get_host_metrics(host, from, to)
  resources.each_with_object(Hash.new { |h,k| h[k] = {} }) do |name,hash|
    Malsh.host_metrics(host["id"], name, from, to).metrics.each do |v|
      hash[v.time][name] = v.value
    end
  end
end

.get_max_usage(host, from, to) ⇒ Object



43
44
45
46
47
# File 'lib/malsh/host_metrics/base.rb', line 43

def get_max_usage(host, from, to)
  host_metrics = get_host_metrics(host, from, to)
  max = get_max_value(host_metrics) if host_metrics
  normalize_result(max, host) if max
end

.get_max_value(host_metrics) ⇒ Object



23
24
25
# File 'lib/malsh/host_metrics/base.rb', line 23

def get_max_value(host_metrics)
  []
end

.lower?(value) ⇒ Boolean



35
36
37
# File 'lib/malsh/host_metrics/base.rb', line 35

def lower?(value)
  value < Malsh.options[option_name]
end

.normalize_result(max, host) ⇒ Object



27
28
29
# File 'lib/malsh/host_metrics/base.rb', line 27

def normalize_result(max, host)
  []
end

.option_nameObject



39
40
41
# File 'lib/malsh/host_metrics/base.rb', line 39

def option_name
  nil
end

.resourcesObject



19
20
21
# File 'lib/malsh/host_metrics/base.rb', line 19

def resources
  []
end