Class: Procmon::ProcessConditions::CpuUsage

Inherits:
ProcessCondition show all
Defined in:
lib/procmon/process_conditions/cpu_usage.rb

Instance Attribute Summary

Attributes inherited from ProcessCondition

#actions

Instance Method Summary collapse

Methods inherited from ProcessCondition

#format_value

Constructor Details

#initialize(options = {}) ⇒ CpuUsage

Returns a new instance of CpuUsage.



4
5
6
7
8
9
10
11
12
13
# File 'lib/procmon/process_conditions/cpu_usage.rb', line 4

def initialize(options = {})
  super(options)
  @below = options[:below]
  @above = options[: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



19
20
21
22
23
24
25
26
27
# File 'lib/procmon/process_conditions/cpu_usage.rb', line 19

def check(value)
  if @below && @above
    value < @below && value > @above
  elsif @below
    value < @below 
  elsif @above
    value > @above
  end
end

#descriptionObject



29
30
31
32
33
34
35
# File 'lib/procmon/process_conditions/cpu_usage.rb', line 29

def description
  ret = "Cpu usage is "
  conditions = {}
  conditions[:below] = @options[:below] if @options[:below]
  conditions[:above] = @options[:above] if @options[:above]
  ret += conditions.inspect
end

#run(pid) ⇒ Object



15
16
17
# File 'lib/procmon/process_conditions/cpu_usage.rb', line 15

def run(pid)
  System.cpu_usage(pid).to_f
end