Class: AlertMachine::Watcher
- Inherits:
-
Object
- Object
- AlertMachine::Watcher
- Defined in:
- lib/alert_machine.rb
Direct Known Subclasses
Class Method Summary collapse
- .assert(conditions, msg = nil, caller = caller) ⇒ Object
-
.run_command(machines, cmd) ⇒ Object
Run a command on a set of machines.
-
.watch(opts = {}, caller = caller, &block) ⇒ Object
Options: The below options can also be overridden via config/alert_machine.yml.
-
.watch_process(machines, opts = {}) ⇒ Object
Make sure the process keeps running.
Class Method Details
.assert(conditions, msg = nil, caller = caller) ⇒ Object
30 31 32 |
# File 'lib/alert_machine.rb', line 30 def self.assert(conditions, msg = nil, caller = caller) AlertMachine.current_task.assert(conditions, msg, caller) end |
.run_command(machines, cmd) ⇒ Object
Run a command on a set of machines.
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/alert_machine.rb', line 58 def self.run_command(machines, cmd) machines = [machines].flatten require 'rye' set = Rye::Set.new(machines.join(","), :parallel => true) machines.each { |m| set.add_box(Rye::Box.new(m, AlertMachine.ssh_config.merge(:safe => false))) } puts "executing on #{machines}: #{cmd}" res = set.execute(cmd).group_by {|ry| ry.box.hostname }.sort_by {|name, op| machines.index(name) } res.each { |machine, op| puts "[#{machine}]\n#{op.join("\n")}\n" } end |
.watch(opts = {}, caller = caller, &block) ⇒ Object
Options:
The below can also be overridden via config/alert_machine.yml
-
interval:
Seconds between each run, during the steady state. 5 min default.
-
interval_error:
How soon to check again, in-case an error occurred. (interval)/5 default.
-
from, to:
Comma seperated list of emails, to bother when there are alerts. defaults to whatever was specified in the config file.
-
retries:
Number of times to try before alerting on error. Defaults to 1.
-
dont_check_long_processes:
Don't assert if my watch took too long to run. [false defaults]
26 27 28 |
# File 'lib/alert_machine.rb', line 26 def self.watch(opts = {}, caller = caller, &block) AlertMachine.tasks << RunTask.new(opts, block, caller) end |
.watch_process(machines, opts = {}) ⇒ Object
Make sure the process keeps running. machines can be one or many.
Options:
One or more of the below constraints. Any of the below can either be a single element or an array. (eg. multiple ports)
-
port:
Ensure the port is open.
-
pid_file:
Make sure the pid file exists and the process corresponding to it, is alive.
-
grep:
Executes `ps aux | grep <string>` to ensure process is running.
Other usual options of watcher, mentioned above.
52 53 54 55 |
# File 'lib/alert_machine.rb', line 52 def self.watch_process(machines, opts = {}) machines = [machines].flatten Process.watch(machines, opts, caller) end |