Class: Cognizant::Process::Conditions::MemoryUsage

Inherits:
PollCondition
  • Object
show all
Defined in:
lib/cognizant/process/conditions/memory_usage.rb

Constant Summary collapse

MB =
1024 ** 2
FORMAT_STR =
"%d%s"
MB_LABEL =
"MB"
KB_LABEL =
"KB"

Instance Method Summary collapse

Methods inherited from PollCondition

#initialize

Constructor Details

This class inherits a constructor from Cognizant::Process::Conditions::PollCondition

Instance Method Details

#check(value) ⇒ Object


14
15
16
# File 'lib/cognizant/process/conditions/memory_usage.rb', line 14

def check(value)
  value.kilobytes > @options[:above].to_f
end

#format_value(value) ⇒ Object


18
19
20
21
22
23
24
# File 'lib/cognizant/process/conditions/memory_usage.rb', line 18

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


10
11
12
# File 'lib/cognizant/process/conditions/memory_usage.rb', line 10

def run(pid)
  Cognizant::System.memory_usage(pid).to_f
end