Class: Procmon::ProcessConditions::MemUsage
- Inherits:
-
ProcessCondition
- Object
- ProcessCondition
- Procmon::ProcessConditions::MemUsage
- Defined in:
- lib/procmon/process_conditions/mem_usage.rb
Constant Summary collapse
- MB =
1024 ** 2
- FORMAT_STR =
"%d%s"
- MB_LABEL =
"MB"
- KB_LABEL =
"KB"
Instance Attribute Summary
Attributes inherited from ProcessCondition
Instance Method Summary collapse
- #check(value) ⇒ Object
- #description ⇒ Object
- #format_value(value) ⇒ Object
-
#initialize(options = {}) ⇒ MemUsage
constructor
A new instance of MemUsage.
- #run(pid) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ MemUsage
Returns a new instance of MemUsage.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/procmon/process_conditions/mem_usage.rb', line 9 def initialize( = {}) super() @below = [:below] @above = [:above] if @below && @above && @below < @above raise "Invalid range for mem check condition" elsif @below.nil? && @above.nil? raise "Invalid range for mem check condition" end end |
Instance Method Details
#check(value) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/procmon/process_conditions/mem_usage.rb', line 25 def check(value) if @below && @above value.kilobytes < @below && value.kilobytes > @above elsif @below value.kilobytes < @below elsif @above value.kilobytes > @above end end |
#description ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/procmon/process_conditions/mem_usage.rb', line 43 def description ret = "Memory usage is " conditions = {} conditions[:below] = @options[:below] if @options[:below] conditions[:above] = @options[:above] if @options[:above] ret += conditions.inspect end |
#format_value(value) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/procmon/process_conditions/mem_usage.rb', line 35 def format_value(value) if value.kilobytes >= MB FORMAT_STR % [(value / 1024).round, MB_LABEL] else FORMAT_STR % [value, KB_LABEL] end end |
#run(pid) ⇒ Object
20 21 22 23 |
# File 'lib/procmon/process_conditions/mem_usage.rb', line 20 def run(pid) # rss is on the 5th col System.memory_usage(pid).to_f end |