Class: EventedBluepill::ProcessConditions::MemUsage

Inherits:
ProcessCondition
  • Object
show all
Defined in:
lib/evented_bluepill/process_conditions/mem_usage.rb

Constant Summary collapse

KB =
1024.0
MB =
KB ** 2
FORMAT_STR =
"%.1f%s"
MB_LABEL =
"MB"
KB_LABEL =
"KB"

Instance Attribute Summary

Attributes inherited from ProcessCondition

#every, #fires, #logger, #name, #process, #process_condition

Instance Method Summary collapse

Methods inherited from ProcessCondition

#clear_history!, #to_s

Constructor Details

#initialize(name, process, options = {}) ⇒ MemUsage

Returns a new instance of MemUsage.



17
18
19
20
21
# File 'lib/evented_bluepill/process_conditions/mem_usage.rb', line 17

def initialize(name, process, options = {})
  @below = options[:below]

  super
end

Instance Method Details

#check(value) ⇒ Object



28
29
30
# File 'lib/evented_bluepill/process_conditions/mem_usage.rb', line 28

def check(value)
  value < @below
end

#format_value(value) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/evented_bluepill/process_conditions/mem_usage.rb', line 32

def format_value(value)
  if value >= MB
    FORMAT_STR % [(value / MB), MB_LABEL]
  else
    FORMAT_STR % [(value / KB), KB_LABEL]
  end
end

#runObject



23
24
25
26
# File 'lib/evented_bluepill/process_conditions/mem_usage.rb', line 23

def run
  # rss is on the 5th col
  EventedBluepill::System.memory_usage(process.actual_pid).to_f.kilobytes
end