eye 0.7 → 0.8.celluloid15

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.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +141 -0
  3. data/.travis.yml +5 -3
  4. data/CHANGES.md +9 -1
  5. data/README.md +5 -2
  6. data/Rakefile +6 -6
  7. data/bin/leye +9 -4
  8. data/bin/loader_eye +14 -15
  9. data/examples/custom_check.eye +24 -0
  10. data/examples/custom_trigger.eye +30 -0
  11. data/examples/delayed_job.eye +3 -3
  12. data/examples/dependency.eye +10 -11
  13. data/examples/leye_example/Eyefile +10 -0
  14. data/examples/notify.eye +3 -4
  15. data/examples/plugin/main.eye +5 -5
  16. data/examples/plugin/plugin.rb +10 -2
  17. data/examples/process_thin.rb +8 -8
  18. data/examples/processes/em.rb +18 -12
  19. data/examples/processes/forking.rb +5 -5
  20. data/examples/processes/sample.rb +46 -44
  21. data/examples/puma.eye +9 -8
  22. data/examples/rbenv.eye +5 -5
  23. data/examples/sidekiq.eye +3 -3
  24. data/examples/stress_test.eye +4 -4
  25. data/examples/syslog.eye +1 -1
  26. data/examples/test.eye +1 -2
  27. data/examples/thin-farm.eye +7 -8
  28. data/examples/triggers.eye +13 -15
  29. data/examples/unicorn.eye +12 -13
  30. data/eye.gemspec +16 -14
  31. data/lib/eye.rb +2 -3
  32. data/lib/eye/application.rb +5 -6
  33. data/lib/eye/checker.rb +44 -25
  34. data/lib/eye/checker/children_count.rb +1 -1
  35. data/lib/eye/checker/file_ctime.rb +1 -1
  36. data/lib/eye/checker/http.rb +13 -15
  37. data/lib/eye/checker/nop.rb +1 -0
  38. data/lib/eye/checker/socket.rb +60 -63
  39. data/lib/eye/checker/ssl_socket.rb +5 -5
  40. data/lib/eye/child_process.rb +6 -4
  41. data/lib/eye/cli.rb +74 -46
  42. data/lib/eye/cli/commands.rb +4 -5
  43. data/lib/eye/cli/render.rb +61 -41
  44. data/lib/eye/cli/server.rb +19 -16
  45. data/lib/eye/client.rb +1 -0
  46. data/lib/eye/config.rb +36 -33
  47. data/lib/eye/controller.rb +2 -3
  48. data/lib/eye/controller/commands.rb +1 -1
  49. data/lib/eye/controller/helpers.rb +2 -2
  50. data/lib/eye/controller/load.rb +19 -17
  51. data/lib/eye/controller/options.rb +1 -5
  52. data/lib/eye/controller/send_command.rb +21 -23
  53. data/lib/eye/controller/status.rb +17 -14
  54. data/lib/eye/dsl.rb +6 -1
  55. data/lib/eye/dsl/application_opts.rb +4 -3
  56. data/lib/eye/dsl/chain.rb +2 -2
  57. data/lib/eye/dsl/child_process_opts.rb +3 -3
  58. data/lib/eye/dsl/config_opts.rb +7 -7
  59. data/lib/eye/dsl/group_opts.rb +3 -3
  60. data/lib/eye/dsl/helpers.rb +1 -1
  61. data/lib/eye/dsl/main.rb +4 -3
  62. data/lib/eye/dsl/opts.rb +31 -28
  63. data/lib/eye/dsl/process_opts.rb +13 -7
  64. data/lib/eye/dsl/pure_opts.rb +13 -9
  65. data/lib/eye/dsl/validation.rb +48 -35
  66. data/lib/eye/group.rb +23 -8
  67. data/lib/eye/group/chain.rb +6 -6
  68. data/lib/eye/loader.rb +3 -3
  69. data/lib/eye/local.rb +9 -4
  70. data/lib/eye/logger.rb +11 -4
  71. data/lib/eye/notify.rb +10 -6
  72. data/lib/eye/notify/jabber.rb +1 -1
  73. data/lib/eye/notify/mail.rb +2 -2
  74. data/lib/eye/notify/slack.rb +4 -3
  75. data/lib/eye/process.rb +2 -0
  76. data/lib/eye/process/children.rb +4 -4
  77. data/lib/eye/process/commands.rb +38 -39
  78. data/lib/eye/process/config.rb +22 -16
  79. data/lib/eye/process/controller.rb +5 -19
  80. data/lib/eye/process/data.rb +11 -9
  81. data/lib/eye/process/monitor.rb +86 -76
  82. data/lib/eye/process/notify.rb +10 -10
  83. data/lib/eye/process/scheduler.rb +36 -31
  84. data/lib/eye/process/states.rb +7 -5
  85. data/lib/eye/process/states_history.rb +9 -3
  86. data/lib/eye/process/system.rb +35 -20
  87. data/lib/eye/process/trigger.rb +1 -5
  88. data/lib/eye/process/watchers.rb +12 -9
  89. data/lib/eye/reason.rb +4 -1
  90. data/lib/eye/server.rb +3 -2
  91. data/lib/eye/system.rb +22 -15
  92. data/lib/eye/system_resources.rb +17 -8
  93. data/lib/eye/trigger.rb +18 -16
  94. data/lib/eye/trigger/check_dependency.rb +7 -4
  95. data/lib/eye/trigger/flapping.rb +24 -7
  96. data/lib/eye/trigger/starting_guard.rb +7 -6
  97. data/lib/eye/trigger/stop_children.rb +2 -2
  98. data/lib/eye/trigger/transition.rb +1 -1
  99. data/lib/eye/trigger/wait_dependency.rb +3 -2
  100. data/lib/eye/utils.rb +4 -3
  101. data/lib/eye/utils/alive_array.rb +9 -4
  102. data/lib/eye/utils/celluloid_chain.rb +12 -10
  103. data/lib/eye/utils/mini_active_support.rb +16 -16
  104. data/lib/eye/utils/pmap.rb +2 -0
  105. data/lib/eye/utils/tail.rb +2 -2
  106. metadata +39 -8
  107. data/lib/eye/utils/leak_19.rb +0 -10
@@ -10,14 +10,14 @@ def sidekiq_process(proxy, name)
10
10
  daemonize true
11
11
  stop_signals [:USR1, 0, :TERM, 10.seconds, :KILL]
12
12
 
13
- check :cpu, :every => 30, :below => 100, :times => 5
14
- check :memory, :every => 30, :below => 300.megabytes, :times => 5
13
+ check :cpu, every: 30, below: 100, times: 5
14
+ check :memory, every: 30, below: 300.megabytes, times: 5
15
15
  end
16
16
  end
17
17
 
18
18
  Eye.application :sidekiq_test do
19
19
  working_dir File.expand_path(File.join(File.dirname(__FILE__), %w[ processes ]))
20
- env "RAILS_ENV" => 'production'
20
+ env 'RAILS_ENV' => 'production'
21
21
 
22
22
  sidekiq_process self, :sidekiq
23
23
  end
@@ -3,16 +3,16 @@
3
3
  PREFIX = ENV['PRE'] || ENV['EYE_V'] || 1
4
4
 
5
5
  Eye.app :stress_test do
6
- working_dir "/tmp"
6
+ working_dir '/tmp'
7
7
 
8
8
  100.times do |i|
9
9
  process "sleep-#{i}" do
10
10
  pid_file "sleep-#{PREFIX}-#{i}.pid"
11
- start_command "sleep 120"
11
+ start_command 'sleep 120'
12
12
  daemonize true
13
13
 
14
- checks :cpu, :every => 5.seconds, :below => 10, :times => 5
15
- checks :memory, :every => 6.seconds, :below => 50.megabytes, :times => 5
14
+ checks :cpu, every: 5.seconds, below: 10, times: 5
15
+ checks :memory, every: 6.seconds, below: 50.megabytes, times: 5
16
16
  end
17
17
  end
18
18
  end
@@ -7,7 +7,7 @@ end
7
7
 
8
8
  Eye.app :syslog_test do
9
9
  process :some do
10
- pid_file "/tmp/syslog_test.pid"
10
+ pid_file '/tmp/syslog_test.pid'
11
11
  start_command "ruby -e 'loop { p Time.now; sleep 1 }'"
12
12
  daemonize!
13
13
  stdall syslog
@@ -66,7 +66,7 @@ Eye.application 'test' do
66
66
  end
67
67
 
68
68
  # eventmachine process, daemonized with eye
69
- process :event_machine do |p|
69
+ process :event_machine do
70
70
  pid_file 'em.pid'
71
71
  start_command 'ruby em.rb'
72
72
  stdout 'em.log'
@@ -86,5 +86,4 @@ Eye.application 'test' do
86
86
  check :http, url: 'http://127.0.0.1:33233/hello', pattern: /World/,
87
87
  every: 5.seconds, times: [2, 3], timeout: 1.second
88
88
  end
89
-
90
89
  end
@@ -1,30 +1,29 @@
1
1
  RUBY = 'ruby'
2
2
  BUNDLE = 'bundle'
3
3
 
4
- Eye.load("process_thin.rb")
4
+ Eye.load('process_thin.rb')
5
5
 
6
6
  Eye.config do
7
- logger "/tmp/eye.log"
7
+ logger '/tmp/eye.log'
8
8
  end
9
9
 
10
10
  Eye.app 'thin-farm' do
11
11
  working_dir File.expand_path(File.join(File.dirname(__FILE__), %w[ processes ]))
12
- env "RAILS_ENV" => "production"
12
+ env 'RAILS_ENV' => 'production'
13
13
 
14
14
  # more about stop_on_delete: https://github.com/kostya/eye/wiki/About-stop_on_delete-=-true
15
15
  stop_on_delete true
16
16
 
17
- trigger :flapping, :times => 10, :within => 1.minute
18
- check :memory, :below => 60.megabytes, :every => 30.seconds, :times => 5
17
+ trigger :flapping, times: 10, within: 1.minute
18
+ check :memory, below: 60.megabytes, every: 30.seconds, times: 5
19
19
  start_timeout 30.seconds
20
20
 
21
21
  group :web do
22
- chain :action => :restart, :grace => 5.seconds
23
- chain :action => :start, :grace => 0.2.seconds
22
+ chain action: :restart, grace: 5.seconds
23
+ chain action: :start, grace: 0.2.seconds
24
24
 
25
25
  (5555..5560).each do |port|
26
26
  thin self, port
27
27
  end
28
28
  end
29
-
30
29
  end
@@ -5,15 +5,14 @@
5
5
  # process.execute_sync(cmd, opts)
6
6
 
7
7
  Eye.config do
8
- logger "/tmp/eye.log"
8
+ logger '/tmp/eye.log'
9
9
  end
10
10
 
11
11
  Eye.app :triggers do
12
-
13
12
  # Execute shell command before process start
14
13
  process :a do
15
- pid_file "/tmp/a.pid"
16
- start_command "sleep 100"
14
+ pid_file '/tmp/a.pid'
15
+ start_command 'sleep 100'
17
16
  daemonize true
18
17
 
19
18
  # send message async which sendxmpp, before process start
@@ -24,41 +23,40 @@ Eye.app :triggers do
24
23
 
25
24
  # Touch some file before process start, remove file after process die
26
25
  process :b do
27
- pid_file "/tmp/b.pid"
28
- start_command "sleep 100"
26
+ pid_file '/tmp/b.pid'
27
+ start_command 'sleep 100'
29
28
  daemonize true
30
29
 
31
30
  # before process starting, touch some file
32
31
  trigger :transition1, to: :starting, do: -> {
33
- process.execute_sync "touch /tmp/bla.file"
32
+ process.execute_sync 'touch /tmp/bla.file'
34
33
  }
35
34
 
36
35
  # after process, crashed, or stopped, remove that file
37
36
  trigger :transition2, to: :down, do: -> {
38
- process.execute_sync "rm /tmp/bla.file"
37
+ process.execute_sync 'rm /tmp/bla.file'
39
38
  }
40
39
  end
41
40
 
42
41
  # With restart :c process, send restart to process :a
43
42
  process :c do
44
- pid_file "/tmp/c.pid"
45
- start_command "sleep 100"
43
+ pid_file '/tmp/c.pid'
44
+ start_command 'sleep 100'
46
45
  daemonize true
47
46
 
48
47
  app_name = app.name
49
- trigger :transition, :event => :restarting, :do => ->{
50
- info "send restarting to :a"
48
+ trigger :transition, event: :restarting, do: ->{
49
+ info 'send restarting to :a'
51
50
  Eye::Control.command('restart', "#{app_name}:a")
52
51
  }
53
52
  end
54
53
 
55
54
  # process d cant start, until file /tmp/bla contains string 'bla'
56
55
  process :d do
57
- pid_file "/tmp/d.pid"
58
- start_command "sleep 100"
56
+ pid_file '/tmp/d.pid'
57
+ start_command 'sleep 100'
59
58
  daemonize true
60
59
 
61
60
  trigger :starting_guard, every: 5.seconds, should: -> { `cat /tmp/bla` =~ /bla/ }
62
61
  end
63
-
64
62
  end
@@ -3,37 +3,36 @@
3
3
  RUBY = '/usr/local/ruby/1.9.3/bin/ruby' # ruby on the server
4
4
  RAILS_ENV = 'production'
5
5
 
6
- Eye.application "rails_unicorn" do
7
- env "RAILS_ENV" => RAILS_ENV
6
+ Eye.application 'rails_unicorn' do
7
+ env 'RAILS_ENV' => RAILS_ENV
8
8
 
9
9
  # unicorn requires to be `ruby` in path (for soft restart)
10
- env "PATH" => "#{File.dirname(RUBY)}:#{ENV['PATH']}"
10
+ env 'PATH' => "#{File.dirname(RUBY)}:#{ENV['PATH']}"
11
11
 
12
12
  working_dir File.expand_path(File.join(File.dirname(__FILE__), %w[ processes ]))
13
13
 
14
- process("unicorn") do
15
- pid_file "tmp/pids/unicorn.pid"
14
+ process('unicorn') do
15
+ pid_file 'tmp/pids/unicorn.pid'
16
16
  start_command "#{RUBY} ./bin/unicorn -Dc ./config/unicorn.rb -E #{RAILS_ENV}"
17
- stdall "log/unicorn.log"
17
+ stdall 'log/unicorn.log'
18
18
 
19
19
  # stop signals:
20
20
  # http://unicorn.bogomips.org/SIGNALS.html
21
21
  stop_signals [:TERM, 10.seconds]
22
22
 
23
23
  # soft restart
24
- restart_command "kill -USR2 {PID}"
24
+ restart_command 'kill -USR2 {PID}'
25
25
 
26
- check :cpu, :every => 30, :below => 80, :times => 3
27
- check :memory, :every => 30, :below => 150.megabytes, :times => [3,5]
26
+ check :cpu, every: 30, below: 80, times: 3
27
+ check :memory, every: 30, below: 150.megabytes, times: [3, 5]
28
28
 
29
29
  start_timeout 100.seconds
30
30
  restart_grace 30.seconds
31
31
 
32
32
  monitor_children do
33
- stop_command "kill -QUIT {PID}"
34
- check :cpu, :every => 30, :below => 80, :times => 3
35
- check :memory, :every => 30, :below => 150.megabytes, :times => [3,5]
33
+ stop_command 'kill -QUIT {PID}'
34
+ check :cpu, every: 30, below: 80, times: 3
35
+ check :memory, every: 30, below: 150.megabytes, times: [3, 5]
36
36
  end
37
37
  end
38
-
39
38
  end
@@ -1,29 +1,29 @@
1
1
  require File.expand_path('../lib/eye', __FILE__)
2
2
 
3
3
  Gem::Specification.new do |gem|
4
- gem.authors = "Konstantin Makarchev"
5
- gem.email = "eye-rb@googlegroups.com"
4
+ gem.authors = 'Konstantin Makarchev'
5
+ gem.email = 'eye-rb@googlegroups.com'
6
6
 
7
7
  gem.description = gem.summary = \
8
- %q{Process monitoring tool. Inspired from Bluepill and God. Requires Ruby(MRI) >= 1.9.3-p194. Uses Celluloid and Celluloid::IO.}
9
- gem.homepage = "http://github.com/kostya/eye"
8
+ 'Process monitoring tool. Inspired from Bluepill and God. Requires Ruby(MRI) >= 1.9.3-p194. Uses Celluloid and Celluloid::IO.'
9
+ gem.homepage = 'http://github.com/kostya/eye'
10
10
 
11
- gem.files = `git ls-files`.split($\).reject{|n| n =~ %r[png|gif\z]}.reject{|n| n =~ %r[^(test|spec|features)/]}
12
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
- #gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
- gem.name = "eye"
15
- gem.require_paths = ["lib"]
11
+ gem.files = `git ls-files`.split($\).reject { |n| n =~ %r[png|gif\z] }.reject { |n| n =~ %r[^(test|spec|features)/] }
12
+ gem.executables = gem.files.grep(%r[^bin/]).map { |f| File.basename(f) }
13
+ # gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = 'eye'
15
+ gem.require_paths = ['lib']
16
16
  gem.version = Eye::VERSION
17
- gem.license = "MIT"
17
+ gem.license = 'MIT'
18
18
 
19
19
  gem.required_ruby_version = '>= 1.9.2'
20
20
  gem.required_rubygems_version = '>= 1.3.6'
21
21
 
22
- gem.add_dependency 'celluloid', '~> 0.16.0'
23
- gem.add_dependency 'celluloid-io', '~> 0.16.0'
22
+ gem.add_dependency 'celluloid', '~> 0.15.0'
23
+ gem.add_dependency 'celluloid-io', '~> 0.15.0'
24
24
  gem.add_dependency 'state_machine'
25
25
  gem.add_dependency 'thor'
26
- gem.add_dependency 'sigar', '~> 0.7.3'
26
+ gem.add_dependency 'sigar', '~> 0.7.3'
27
27
 
28
28
  gem.add_development_dependency 'rake'
29
29
  gem.add_development_dependency 'rspec', '< 2.14'
@@ -31,13 +31,15 @@ Gem::Specification.new do |gem|
31
31
  gem.add_development_dependency 'ruby-graphviz'
32
32
  gem.add_development_dependency 'forking'
33
33
  gem.add_development_dependency 'fakeweb'
34
- gem.add_development_dependency 'eventmachine', ">= 1.0.3"
34
+ gem.add_development_dependency 'eventmachine', '>= 1.0.3'
35
35
  gem.add_development_dependency 'sinatra'
36
36
  gem.add_development_dependency 'thin'
37
37
  gem.add_development_dependency 'xmpp4r'
38
38
  gem.add_development_dependency 'slack-notifier'
39
39
  gem.add_development_dependency 'coveralls'
40
+ gem.add_development_dependency 'tins', '1.6.0' # for coveralls
40
41
  gem.add_development_dependency 'simplecov', '>= 0.8.1'
41
42
  gem.add_development_dependency 'parallel_tests', '<= 1.3.1'
42
43
  gem.add_development_dependency 'parallel_split_test'
44
+ gem.add_development_dependency 'rubocop'
43
45
  end
data/lib/eye.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Eye
2
- VERSION = "0.7"
2
+ VERSION = '0.8.celluloid15'
3
3
  ABOUT = "Eye v#{VERSION} (c) 2012-2015 @kostya"
4
4
  PROCLINE = "eye monitoring v#{VERSION}"
5
5
 
@@ -8,7 +8,7 @@ module Eye
8
8
  autoload :Server, 'eye/server'
9
9
  autoload :Logger, 'eye/logger'
10
10
  autoload :System, 'eye/system'
11
- autoload :SystemResources,'eye/system_resources'
11
+ autoload :SystemResources, 'eye/system_resources'
12
12
  autoload :Checker, 'eye/checker'
13
13
  autoload :Trigger, 'eye/trigger'
14
14
  autoload :Group, 'eye/group'
@@ -21,7 +21,6 @@ module Eye
21
21
  autoload :Config, 'eye/config'
22
22
  autoload :Reason, 'eye/reason'
23
23
  autoload :Sigar, 'eye/sigar'
24
-
25
24
  autoload :Controller, 'eye/controller'
26
25
  autoload :Control, 'eye/control'
27
26
  autoload :Cli, 'eye/cli'
@@ -21,13 +21,12 @@ class Eye::Application
21
21
  @groups << group
22
22
  end
23
23
 
24
- # sort processes in name order
25
24
  def resort_groups
26
- @groups = @groups.sort { |a, b| a.hidden ? 1 : (b.hidden ? -1 : (a.name <=> b.name)) }
25
+ @groups.sort! # used group method <=> to compare
27
26
  end
28
27
 
29
- def status_data(debug = false)
30
- h = { name: @name, type: :application, subtree: @groups.map{|gr| gr.status_data(debug) }}
28
+ def status_data(opts = {})
29
+ h = { name: @name, type: :application, subtree: @groups.map { |gr| gr.status_data(opts) } }
31
30
  h[:debug] = debug_data if debug
32
31
  h
33
32
  end
@@ -53,13 +52,13 @@ class Eye::Application
53
52
 
54
53
  def sub_object?(obj)
55
54
  res = @groups.include?(obj)
56
- res = @groups.any?{|gr| gr.sub_object?(obj)} if !res
55
+ res = @groups.any? { |gr| gr.sub_object?(obj) } unless res
57
56
  res
58
57
  end
59
58
 
60
59
  def processes
61
60
  out = []
62
- @groups.each{|gr| out += gr.processes.to_a }
61
+ @groups.each { |gr| out += gr.processes.to_a }
63
62
  Eye::Utils::AliveArray.new(out)
64
63
  end
65
64
 
@@ -1,4 +1,5 @@
1
1
  class Eye::Checker
2
+
2
3
  include Eye::Dsl::Validation
3
4
 
4
5
  autoload :Memory, 'eye/checker/memory'
@@ -6,35 +7,35 @@ class Eye::Checker
6
7
  autoload :Http, 'eye/checker/http'
7
8
  autoload :FileCTime, 'eye/checker/file_ctime'
8
9
  autoload :FileSize, 'eye/checker/file_size'
9
- autoload :FileTouched,'eye/checker/file_touched'
10
+ autoload :FileTouched, 'eye/checker/file_touched'
10
11
  autoload :Socket, 'eye/checker/socket'
11
12
  autoload :SslSocket, 'eye/checker/ssl_socket'
12
13
  autoload :Nop, 'eye/checker/nop'
13
14
  autoload :Runtime, 'eye/checker/runtime'
14
15
  autoload :Cputime, 'eye/checker/cputime'
15
16
  autoload :ChildrenCount, 'eye/checker/children_count'
16
- autoload :ChildrenMemory,'eye/checker/children_memory'
17
+ autoload :ChildrenMemory, 'eye/checker/children_memory'
17
18
 
18
- TYPES = {:memory => 'Memory', :cpu => 'Cpu', :http => 'Http',
19
- :ctime => 'FileCTime', :fsize => 'FileSize', :file_touched => 'FileTouched',
20
- :socket => 'Socket', :nop => 'Nop', :runtime => 'Runtime', :cputime => 'Cputime',
21
- :children_count => "ChildrenCount", :children_memory => "ChildrenMemory", :ssl_socket => 'SslSocket' }
19
+ TYPES = { memory: 'Memory', cpu: 'Cpu', http: 'Http',
20
+ ctime: 'FileCTime', fsize: 'FileSize', file_touched: 'FileTouched',
21
+ socket: 'Socket', nop: 'Nop', runtime: 'Runtime', cputime: 'Cputime',
22
+ children_count: 'ChildrenCount', children_memory: 'ChildrenMemory', ssl_socket: 'SslSocket' }
22
23
 
23
24
  attr_accessor :value, :values, :options, :pid, :type, :check_count, :process
24
25
 
25
26
  param :every, [Fixnum, Float], false, 5
26
27
  param :times, [Fixnum, Array], nil, 1
27
- param :fires, [Symbol, Array], nil, nil, [:stop, :restart, :unmonitor, :start, :delete, :nothing, :notify]
28
+ param :fires, [Symbol, Array, Proc], nil, nil, [:stop, :restart, :unmonitor, :start, :delete, :nothing, :notify]
28
29
  param :initial_grace, [Fixnum, Float]
29
30
  param :skip_initial_fails, [TrueClass, FalseClass]
30
31
 
31
32
  def self.name_and_class(type)
32
33
  type = type.to_sym
33
- return {:name => type, :type => type} if TYPES[type]
34
+ return { name: type, type: type } if TYPES[type]
34
35
 
35
- if type =~ /\A(.*?)_?[0-9]+\z/
36
- ctype = $1.to_sym
37
- return {:name => type, :type => ctype} if TYPES[ctype]
36
+ if type =~ %r[\A(.*?)_?[0-9]+\z]
37
+ ctype = Regexp.last_match(1).to_sym
38
+ return { name: type, type: ctype } if TYPES[ctype]
38
39
  end
39
40
  end
40
41
 
@@ -50,7 +51,7 @@ class Eye::Checker
50
51
  def self.create(pid, options = {}, process = nil)
51
52
  get_class(options[:type]).new(pid, options, process)
52
53
 
53
- rescue Exception, Timeout::Error => ex
54
+ rescue Object => ex
54
55
  log_ex(ex)
55
56
  nil
56
57
  end
@@ -79,11 +80,11 @@ class Eye::Checker
79
80
  end
80
81
 
81
82
  def logger_tag
82
- @process.logger.prefix if @process
83
+ @logger_tag ||= @process ? @process.logger.prefix : nil
83
84
  end
84
85
 
85
86
  def logger_sub_tag
86
- "check:#{check_name}"
87
+ @logger_sub_tag ||= "check:#{check_name}"
87
88
  end
88
89
 
89
90
  def last_human_values
@@ -96,22 +97,24 @@ class Eye::Checker
96
97
  end
97
98
 
98
99
  def check
99
- if initial_grace && (Time.now - @initialized_at < initial_grace)
100
- debug { 'skipped initial grace' }
101
- return true
102
- else
103
- @options[:initial_grace] = nil
100
+ if initial_grace
101
+ if Time.now - @initialized_at < initial_grace
102
+ debug { 'skipped initial grace' }
103
+ return true
104
+ else
105
+ @options[:initial_grace] = nil
106
+ end
104
107
  end
105
108
 
106
109
  @value = get_value_safe
107
110
  @good_value = good?(value)
108
- @values << {:value => @value, :good => @good_value}
111
+ @values << { value: @value, good: @good_value }
109
112
 
110
113
  result = true
111
114
  @check_count += 1
112
115
 
113
116
  if @values.size == max_tries
114
- bad_count = @values.count{|v| !v[:good] }
117
+ bad_count = @values.count { |v| !v[:good] }
115
118
  result = false if bad_count >= min_tries
116
119
  end
117
120
 
@@ -123,10 +126,10 @@ class Eye::Checker
123
126
  end
124
127
  end
125
128
 
126
- info "#{last_human_values} => #{result ? 'OK' : 'Fail'}"
129
+ info { "#{last_human_values} => #{result ? 'OK' : 'Fail'}" }
127
130
  result
128
131
 
129
- rescue Exception, Timeout::Error => ex
132
+ rescue Object => ex
130
133
  log_ex(ex)
131
134
  end
132
135
 
@@ -189,7 +192,12 @@ class Eye::Checker
189
192
  process.notify :warn, "Bounded #{check_name}: #{last_human_values} send to #{actions}"
190
193
 
191
194
  actions.each do |action|
192
- process.schedule action, Eye::Reason.new("bounded #{check_name}")
195
+ reason = Eye::Reason.new("bounded #{check_name}")
196
+ if action.is_a?(Proc)
197
+ process.schedule :execute_proc, reason, &action
198
+ else
199
+ process.schedule action, reason
200
+ end
193
201
  end
194
202
  end
195
203
 
@@ -198,9 +206,11 @@ class Eye::Checker
198
206
  end
199
207
 
200
208
  class Defer < Eye::Checker
209
+
201
210
  def get_value_safe
202
- Celluloid::Future.new{ get_value }.value
211
+ Celluloid::Future.new { get_value }.value
203
212
  end
213
+
204
214
  end
205
215
 
206
216
  def self.register(base)
@@ -214,27 +224,34 @@ class Eye::Checker
214
224
  end
215
225
 
216
226
  class CustomCell < Eye::Checker
227
+
217
228
  def self.inherited(base)
218
229
  super
219
230
  register(base)
220
231
  end
232
+
221
233
  end
222
234
 
223
235
  class Custom < Defer
236
+
224
237
  def self.inherited(base)
225
238
  super
226
239
  register(base)
227
240
  end
241
+
228
242
  end
229
243
 
230
244
  class CustomDefer < Defer
245
+
231
246
  def self.inherited(base)
232
247
  super
233
248
  register(base)
234
249
  end
250
+
235
251
  end
236
252
 
237
253
  class Measure < Eye::Checker
254
+
238
255
  param :below, [Fixnum, Float]
239
256
  param :above, [Fixnum, Float]
240
257
 
@@ -255,5 +272,7 @@ class Eye::Checker
255
272
  '-'
256
273
  end
257
274
  end
275
+
258
276
  end
277
+
259
278
  end