god 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +9 -1
 - data/Manifest.txt +13 -1
 - data/README.txt +2 -0
 - data/Rakefile +2 -2
 - data/examples/gravatar.god +8 -2
 - data/examples/local.god +4 -4
 - data/ext/god/Makefile +149 -0
 - data/ext/god/extconf.rb +8 -0
 - data/ext/god/kqueue_handler.c +122 -0
 - data/ext/god/netlink_handler.c +140 -0
 - data/lib/god.rb +37 -4
 - data/lib/god/conditions/always.rb +9 -1
 - data/lib/god/conditions/cpu_usage.rb +2 -2
 - data/lib/god/conditions/memory_usage.rb +2 -2
 - data/lib/god/conditions/process_exits.rb +28 -0
 - data/lib/god/conditions/process_running.rb +25 -0
 - data/lib/god/event_handler.rb +45 -0
 - data/lib/god/event_handlers/kqueue_handler.rb +15 -0
 - data/lib/god/event_handlers/netlink_handler.rb +11 -0
 - data/lib/god/hub.rb +84 -0
 - data/lib/god/meddle.rb +1 -17
 - data/lib/god/metric.rb +60 -0
 - data/lib/god/timer.rb +21 -26
 - data/lib/god/watch.rb +90 -58
 - data/test/configs/real.rb +2 -5
 - data/test/configs/test.rb +75 -0
 - data/test/helper.rb +1 -0
 - data/test/test_condition.rb +1 -1
 - data/test/test_god.rb +3 -2
 - data/test/test_metric.rb +60 -0
 - data/test/test_timer.rb +21 -11
 - data/test/test_watch.rb +49 -78
 - metadata +20 -6
 - data/lib/god/conditions/process_not_running.rb +0 -22
 
    
        data/test/test_watch.rb
    CHANGED
    
    | 
         @@ -5,15 +5,19 @@ class TestWatch < Test::Unit::TestCase 
     | 
|
| 
       5 
5 
     | 
    
         
             
                @watch = Watch.new(nil)
         
     | 
| 
       6 
6 
     | 
    
         
             
              end
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
               
     | 
| 
       9 
     | 
    
         
            -
                assert_equal [], @watch.conditions[:start]
         
     | 
| 
       10 
     | 
    
         
            -
              end
         
     | 
| 
      
 8 
     | 
    
         
            +
              # new
         
     | 
| 
       11 
9 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
              def  
     | 
| 
       13 
     | 
    
         
            -
                assert_equal [], @watch. 
     | 
| 
      
 10 
     | 
    
         
            +
              def test_new_should_have_no_behaviors
         
     | 
| 
      
 11 
     | 
    
         
            +
                assert_equal [], @watch.behaviors
         
     | 
| 
       14 
12 
     | 
    
         
             
              end
         
     | 
| 
       15 
13 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
              def  
     | 
| 
      
 14 
     | 
    
         
            +
              def test_new_should_have_no_metrics
         
     | 
| 
      
 15 
     | 
    
         
            +
                Watch::VALID_STATES.each do |state|
         
     | 
| 
      
 16 
     | 
    
         
            +
                  assert_equal [], @watch.metrics[state]
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
                
         
     | 
| 
      
 20 
     | 
    
         
            +
              def test_new_should_have_standard_attributes
         
     | 
| 
       17 
21 
     | 
    
         
             
                assert_nothing_raised do
         
     | 
| 
       18 
22 
     | 
    
         
             
                  @watch.name = 'foo'
         
     | 
| 
       19 
23 
     | 
    
         
             
                  @watch.start = 'start'
         
     | 
| 
         @@ -24,100 +28,67 @@ class TestWatch < Test::Unit::TestCase 
     | 
|
| 
       24 
28 
     | 
    
         
             
                end
         
     | 
| 
       25 
29 
     | 
    
         
             
              end
         
     | 
| 
       26 
30 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
               
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
              def test_start_if_should_modify_action_within_scope
         
     | 
| 
       30 
     | 
    
         
            -
                assert_equal nil, @watch.instance_variable_get(:@action)
         
     | 
| 
       31 
     | 
    
         
            -
                @watch.start_if do |w|
         
     | 
| 
       32 
     | 
    
         
            -
                  assert_equal :start, @watch.instance_variable_get(:@action)
         
     | 
| 
       33 
     | 
    
         
            -
                end
         
     | 
| 
       34 
     | 
    
         
            -
                assert_equal nil, @watch.instance_variable_get(:@action)
         
     | 
| 
      
 31 
     | 
    
         
            +
              def test_new_should_have_nil_state
         
     | 
| 
      
 32 
     | 
    
         
            +
                assert_equal nil, @watch.state
         
     | 
| 
       35 
33 
     | 
    
         
             
              end
         
     | 
| 
       36 
34 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
               
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
                end
         
     | 
| 
       42 
     | 
    
         
            -
                assert_equal nil, @watch.instance_variable_get(:@action)
         
     | 
| 
      
 35 
     | 
    
         
            +
              # mutex
         
     | 
| 
      
 36 
     | 
    
         
            +
              
         
     | 
| 
      
 37 
     | 
    
         
            +
              def test_mutex_should_return_the_same_mutex_each_time
         
     | 
| 
      
 38 
     | 
    
         
            +
                assert_equal @watch.mutex, @watch.mutex
         
     | 
| 
       43 
39 
     | 
    
         
             
              end
         
     | 
| 
       44 
40 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
              #  
     | 
| 
      
 41 
     | 
    
         
            +
              # behavior
         
     | 
| 
       46 
42 
     | 
    
         | 
| 
       47 
     | 
    
         
            -
              def  
     | 
| 
       48 
     | 
    
         
            -
                 
     | 
| 
       49 
     | 
    
         
            -
                @watch. 
     | 
| 
       50 
     | 
    
         
            -
                @watch. 
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
                end
         
     | 
| 
       53 
     | 
    
         
            -
                assert_equal 1, @watch.conditions[:start].size
         
     | 
| 
       54 
     | 
    
         
            -
                assert_equal cond, @watch.conditions[:start].first
         
     | 
| 
      
 43 
     | 
    
         
            +
              def test_behavior_should_record_behavior
         
     | 
| 
      
 44 
     | 
    
         
            +
                beh = nil
         
     | 
| 
      
 45 
     | 
    
         
            +
                @watch.behavior(:fake_behavior) { |b| beh = b }
         
     | 
| 
      
 46 
     | 
    
         
            +
                assert_equal 1, @watch.behaviors.size
         
     | 
| 
      
 47 
     | 
    
         
            +
                assert_equal beh, @watch.behaviors.first
         
     | 
| 
       55 
48 
     | 
    
         
             
              end
         
     | 
| 
       56 
49 
     | 
    
         | 
| 
       57 
     | 
    
         
            -
               
     | 
| 
       58 
     | 
    
         
            -
                cond = nil
         
     | 
| 
       59 
     | 
    
         
            -
                @watch.interval = 0
         
     | 
| 
       60 
     | 
    
         
            -
                @watch.restart_if do |w|
         
     | 
| 
       61 
     | 
    
         
            -
                  w.condition(:fake_poll_condition) { |c| cond = c }
         
     | 
| 
       62 
     | 
    
         
            -
                end
         
     | 
| 
       63 
     | 
    
         
            -
                assert_equal 1, @watch.conditions[:restart].size
         
     | 
| 
       64 
     | 
    
         
            -
                assert_equal cond, @watch.conditions[:restart].first
         
     | 
| 
       65 
     | 
    
         
            -
              end
         
     | 
| 
      
 50 
     | 
    
         
            +
              # transition
         
     | 
| 
       66 
51 
     | 
    
         | 
| 
       67 
     | 
    
         
            -
              def  
     | 
| 
      
 52 
     | 
    
         
            +
              def test_transition_should_abort_on_invalid_start_state
         
     | 
| 
       68 
53 
     | 
    
         
             
                assert_raise AbortCalledError do
         
     | 
| 
       69 
     | 
    
         
            -
                  @watch. 
     | 
| 
      
 54 
     | 
    
         
            +
                  @watch.transition(:foo, :bar)
         
     | 
| 
       70 
55 
     | 
    
         
             
                end
         
     | 
| 
       71 
56 
     | 
    
         
             
              end
         
     | 
| 
       72 
57 
     | 
    
         | 
| 
       73 
     | 
    
         
            -
              def  
     | 
| 
       74 
     | 
    
         
            -
                 
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
      
 58 
     | 
    
         
            +
              def test_transition_should_accept_all_valid_start_states
         
     | 
| 
      
 59 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 60 
     | 
    
         
            +
                  Watch::VALID_STATES.each do |state|
         
     | 
| 
      
 61 
     | 
    
         
            +
                    @watch.transition(state, :bar) { }
         
     | 
| 
      
 62 
     | 
    
         
            +
                  end
         
     | 
| 
       77 
63 
     | 
    
         
             
                end
         
     | 
| 
       78 
     | 
    
         
            -
                assert_equal 1, @watch.conditions[:start].size
         
     | 
| 
       79 
64 
     | 
    
         
             
              end
         
     | 
| 
       80 
65 
     | 
    
         | 
| 
       81 
     | 
    
         
            -
              def  
     | 
| 
       82 
     | 
    
         
            -
                @watch. 
     | 
| 
       83 
     | 
    
         
            -
                @watch. 
     | 
| 
       84 
     | 
    
         
            -
                  w.condition(:fake_poll_condition)
         
     | 
| 
       85 
     | 
    
         
            -
                end
         
     | 
| 
       86 
     | 
    
         
            -
                assert_equal 27, @watch.conditions[:start].first.interval
         
     | 
| 
      
 66 
     | 
    
         
            +
              def test_transition_should_create_and_record_a_metric_for_the_given_start_state
         
     | 
| 
      
 67 
     | 
    
         
            +
                @watch.transition(:init, :start) { }
         
     | 
| 
      
 68 
     | 
    
         
            +
                assert_equal 1, @watch.metrics[:init].size
         
     | 
| 
       87 
69 
     | 
    
         
             
              end
         
     | 
| 
       88 
70 
     | 
    
         | 
| 
       89 
     | 
    
         
            -
               
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
                end
         
     | 
| 
      
 71 
     | 
    
         
            +
              # start_if
         
     | 
| 
      
 72 
     | 
    
         
            +
              
         
     | 
| 
      
 73 
     | 
    
         
            +
              def test_start_if_should_place_a_metric_on_up_state
         
     | 
| 
      
 74 
     | 
    
         
            +
                @watch.start_if { }
         
     | 
| 
      
 75 
     | 
    
         
            +
                assert_equal 1, @watch.metrics[:up].size
         
     | 
| 
       95 
76 
     | 
    
         
             
              end
         
     | 
| 
       96 
77 
     | 
    
         | 
| 
       97 
     | 
    
         
            -
               
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
                    w.condition(:fake_event_condition)
         
     | 
| 
       103 
     | 
    
         
            -
                  end
         
     | 
| 
       104 
     | 
    
         
            -
                end
         
     | 
| 
      
 78 
     | 
    
         
            +
              # restart_if
         
     | 
| 
      
 79 
     | 
    
         
            +
              
         
     | 
| 
      
 80 
     | 
    
         
            +
              def test_restart_if_should_place_a_metric_on_up_state
         
     | 
| 
      
 81 
     | 
    
         
            +
                @watch.restart_if { }
         
     | 
| 
      
 82 
     | 
    
         
            +
                assert_equal 1, @watch.metrics[:up].size
         
     | 
| 
       105 
83 
     | 
    
         
             
              end
         
     | 
| 
       106 
84 
     | 
    
         | 
| 
       107 
     | 
    
         
            -
               
     | 
| 
       108 
     | 
    
         
            -
             
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
                  end
         
     | 
| 
       112 
     | 
    
         
            -
                end
         
     | 
| 
      
 85 
     | 
    
         
            +
              # canonical_hash_form
         
     | 
| 
      
 86 
     | 
    
         
            +
              
         
     | 
| 
      
 87 
     | 
    
         
            +
              def test_canonical_hash_form_should_convert_symbol_to_hash
         
     | 
| 
      
 88 
     | 
    
         
            +
                assert_equal({true => :foo}, @watch.canonical_hash_form(:foo))
         
     | 
| 
       113 
89 
     | 
    
         
             
              end
         
     | 
| 
       114 
     | 
    
         
            -
             
     | 
| 
       115 
     | 
    
         
            -
              # behavior
         
     | 
| 
       116 
90 
     | 
    
         | 
| 
       117 
     | 
    
         
            -
              def  
     | 
| 
       118 
     | 
    
         
            -
                 
     | 
| 
       119 
     | 
    
         
            -
                @watch.behavior(:fake_behavior) { |b| beh = b }
         
     | 
| 
       120 
     | 
    
         
            -
                assert_equal 1, @watch.behaviors.size
         
     | 
| 
       121 
     | 
    
         
            -
                assert_equal beh, @watch.behaviors.first
         
     | 
| 
      
 91 
     | 
    
         
            +
              def test_canonical_hash_form_should_convert_hash_to_hash
         
     | 
| 
      
 92 
     | 
    
         
            +
                assert_equal({true => :foo}, @watch.canonical_hash_form(true => :foo))
         
     | 
| 
       122 
93 
     | 
    
         
             
              end
         
     | 
| 
       123 
94 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,13 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification 
         
     | 
| 
       2 
     | 
    
         
            -
            rubygems_version: 0.9. 
     | 
| 
      
 2 
     | 
    
         
            +
            rubygems_version: 0.9.2
         
     | 
| 
       3 
3 
     | 
    
         
             
            specification_version: 1
         
     | 
| 
       4 
4 
     | 
    
         
             
            name: god
         
     | 
| 
       5 
5 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       6 
     | 
    
         
            -
              version: 0. 
     | 
| 
       7 
     | 
    
         
            -
            date: 2007-07- 
     | 
| 
      
 6 
     | 
    
         
            +
              version: 0.2.0
         
     | 
| 
      
 7 
     | 
    
         
            +
            date: 2007-07-18 00:00:00 -07:00
         
     | 
| 
       8 
8 
     | 
    
         
             
            summary: Like monit, only awesome
         
     | 
| 
       9 
9 
     | 
    
         
             
            require_paths: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            - lib
         
     | 
| 
      
 11 
     | 
    
         
            +
            - ext
         
     | 
| 
       11 
12 
     | 
    
         
             
            email: tom@rubyisawesome.com
         
     | 
| 
       12 
13 
     | 
    
         
             
            homepage: http://god.rubyforge.org/
         
     | 
| 
       13 
14 
     | 
    
         
             
            rubyforge_project: god
         
     | 
| 
         @@ -36,6 +37,10 @@ files: 
     | 
|
| 
       36 
37 
     | 
    
         
             
            - bin/god
         
     | 
| 
       37 
38 
     | 
    
         
             
            - examples/gravatar.god
         
     | 
| 
       38 
39 
     | 
    
         
             
            - examples/local.god
         
     | 
| 
      
 40 
     | 
    
         
            +
            - ext/god/Makefile
         
     | 
| 
      
 41 
     | 
    
         
            +
            - ext/god/extconf.rb
         
     | 
| 
      
 42 
     | 
    
         
            +
            - ext/god/kqueue_handler.c
         
     | 
| 
      
 43 
     | 
    
         
            +
            - ext/god/netlink_handler.c
         
     | 
| 
       39 
44 
     | 
    
         
             
            - lib/god.rb
         
     | 
| 
       40 
45 
     | 
    
         
             
            - lib/god/base.rb
         
     | 
| 
       41 
46 
     | 
    
         
             
            - lib/god/behavior.rb
         
     | 
| 
         @@ -44,22 +49,30 @@ files: 
     | 
|
| 
       44 
49 
     | 
    
         
             
            - lib/god/conditions/always.rb
         
     | 
| 
       45 
50 
     | 
    
         
             
            - lib/god/conditions/cpu_usage.rb
         
     | 
| 
       46 
51 
     | 
    
         
             
            - lib/god/conditions/memory_usage.rb
         
     | 
| 
       47 
     | 
    
         
            -
            - lib/god/conditions/ 
     | 
| 
      
 52 
     | 
    
         
            +
            - lib/god/conditions/process_exits.rb
         
     | 
| 
      
 53 
     | 
    
         
            +
            - lib/god/conditions/process_running.rb
         
     | 
| 
       48 
54 
     | 
    
         
             
            - lib/god/conditions/timeline.rb
         
     | 
| 
       49 
55 
     | 
    
         
             
            - lib/god/errors.rb
         
     | 
| 
      
 56 
     | 
    
         
            +
            - lib/god/event_handler.rb
         
     | 
| 
      
 57 
     | 
    
         
            +
            - lib/god/event_handlers/kqueue_handler.rb
         
     | 
| 
      
 58 
     | 
    
         
            +
            - lib/god/event_handlers/netlink_handler.rb
         
     | 
| 
      
 59 
     | 
    
         
            +
            - lib/god/hub.rb
         
     | 
| 
       50 
60 
     | 
    
         
             
            - lib/god/meddle.rb
         
     | 
| 
      
 61 
     | 
    
         
            +
            - lib/god/metric.rb
         
     | 
| 
       51 
62 
     | 
    
         
             
            - lib/god/reporter.rb
         
     | 
| 
       52 
63 
     | 
    
         
             
            - lib/god/server.rb
         
     | 
| 
       53 
64 
     | 
    
         
             
            - lib/god/system/process.rb
         
     | 
| 
       54 
65 
     | 
    
         
             
            - lib/god/timer.rb
         
     | 
| 
       55 
66 
     | 
    
         
             
            - lib/god/watch.rb
         
     | 
| 
       56 
67 
     | 
    
         
             
            - test/configs/real.rb
         
     | 
| 
      
 68 
     | 
    
         
            +
            - test/configs/test.rb
         
     | 
| 
       57 
69 
     | 
    
         
             
            - test/helper.rb
         
     | 
| 
       58 
70 
     | 
    
         
             
            - test/suite.rb
         
     | 
| 
       59 
71 
     | 
    
         
             
            - test/test_behavior.rb
         
     | 
| 
       60 
72 
     | 
    
         
             
            - test/test_condition.rb
         
     | 
| 
       61 
73 
     | 
    
         
             
            - test/test_god.rb
         
     | 
| 
       62 
74 
     | 
    
         
             
            - test/test_meddle.rb
         
     | 
| 
      
 75 
     | 
    
         
            +
            - test/test_metric.rb
         
     | 
| 
       63 
76 
     | 
    
         
             
            - test/test_reporter.rb
         
     | 
| 
       64 
77 
     | 
    
         
             
            - test/test_server.rb
         
     | 
| 
       65 
78 
     | 
    
         
             
            - test/test_system_process.rb
         
     | 
| 
         @@ -71,6 +84,7 @@ test_files: 
     | 
|
| 
       71 
84 
     | 
    
         
             
            - test/test_condition.rb
         
     | 
| 
       72 
85 
     | 
    
         
             
            - test/test_god.rb
         
     | 
| 
       73 
86 
     | 
    
         
             
            - test/test_meddle.rb
         
     | 
| 
      
 87 
     | 
    
         
            +
            - test/test_metric.rb
         
     | 
| 
       74 
88 
     | 
    
         
             
            - test/test_reporter.rb
         
     | 
| 
       75 
89 
     | 
    
         
             
            - test/test_server.rb
         
     | 
| 
       76 
90 
     | 
    
         
             
            - test/test_system_process.rb
         
     | 
| 
         @@ -86,8 +100,8 @@ extra_rdoc_files: 
     | 
|
| 
       86 
100 
     | 
    
         
             
            - README.txt
         
     | 
| 
       87 
101 
     | 
    
         
             
            executables: 
         
     | 
| 
       88 
102 
     | 
    
         
             
            - god
         
     | 
| 
       89 
     | 
    
         
            -
            extensions:  
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
      
 103 
     | 
    
         
            +
            extensions: 
         
     | 
| 
      
 104 
     | 
    
         
            +
            - ext/god/extconf.rb
         
     | 
| 
       91 
105 
     | 
    
         
             
            requirements: []
         
     | 
| 
       92 
106 
     | 
    
         | 
| 
       93 
107 
     | 
    
         
             
            dependencies: 
         
     | 
| 
         @@ -1,22 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module God
         
     | 
| 
       2 
     | 
    
         
            -
              module Conditions
         
     | 
| 
       3 
     | 
    
         
            -
                
         
     | 
| 
       4 
     | 
    
         
            -
                class ProcessNotRunning < PollCondition
         
     | 
| 
       5 
     | 
    
         
            -
                  attr_accessor :pid_file
         
     | 
| 
       6 
     | 
    
         
            -
                  
         
     | 
| 
       7 
     | 
    
         
            -
                  def valid?
         
     | 
| 
       8 
     | 
    
         
            -
                    valid = true
         
     | 
| 
       9 
     | 
    
         
            -
                    valid &= complain("You must specify the 'pid_file' attribute for :process_not_running") if self.pid_file.nil?
         
     | 
| 
       10 
     | 
    
         
            -
                    valid
         
     | 
| 
       11 
     | 
    
         
            -
                  end
         
     | 
| 
       12 
     | 
    
         
            -
                
         
     | 
| 
       13 
     | 
    
         
            -
                  def test
         
     | 
| 
       14 
     | 
    
         
            -
                    return false unless File.exist?(self.pid_file)
         
     | 
| 
       15 
     | 
    
         
            -
                    
         
     | 
| 
       16 
     | 
    
         
            -
                    pid = File.open(self.pid_file).read.strip
         
     | 
| 
       17 
     | 
    
         
            -
                    System::Process.new(pid).exists?
         
     | 
| 
       18 
     | 
    
         
            -
                  end
         
     | 
| 
       19 
     | 
    
         
            -
                end
         
     | 
| 
       20 
     | 
    
         
            -
                
         
     | 
| 
       21 
     | 
    
         
            -
              end
         
     | 
| 
       22 
     | 
    
         
            -
            end
         
     |