-
Notifications
You must be signed in to change notification settings - Fork 0
Writing Custom Conditions
Gurpartap edited this page Dec 25, 2012
·
8 revisions
Writing conditions for Cognizant is easy. Here are a few examples to follow:
module Cognizant
class Process
module Conditions
class AlwaysTrue < PollCondition
def run(pid)
1
end
def check(value)
true
end
end
end
end
end
# Usage
process.check :always_true, :every => 2.seconds, :times => 3, :do => :restart
module Cognizant
class Process
module Conditions
class CpuUsage < PollCondition
def initialize(options = {})
@above = options[:above].to_f
end
def run(pid)
Cognizant::System.cpu_usage(pid).to_f
end
def check(value)
value > @above
end
end
end
end
end
# Usage
process.check :cpu_usage, :every => 3.seconds, :above => 60, :times => 3, :do => :stop