what 0.0.16 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,12 +8,10 @@ class What::Modules::CustomModule < What::Modules::Base
8
8
  'world' => 'world'
9
9
  }
10
10
 
11
- # You can use the initialize method to set up any data structures you'll be
12
- # using. If you do write an initialize, make sure to call super to populate
13
- # the @config object.
11
+ # You can use the initialize_module method to set up any data structures
12
+ # you'll be using.
14
13
  # (optional)
15
- def initialize
16
- super
14
+ def initialize_module
17
15
  @hellos = 1
18
16
  end
19
17
 
data/example/what.yml CHANGED
@@ -1,55 +1,60 @@
1
1
  # Config file for the What monitoring system.
2
2
 
3
- ### Choose between JSON and YAML formatting. (default: json)
4
- formatter: json
3
+ # Choose between JSON and YAML formatting.
4
+ #formatter: json
5
5
 
6
- ### Set the polling interval for all services, in seconds. (default: 10)
7
- interval: 10
6
+ # Set the polling interval for all services, in seconds.
7
+ #interval: 10
8
8
 
9
- ### Set an optional token that must be provided as a query string to retrieve
10
- ### status via HTTP.
11
- # secret_token: il1k3tUr7l3z
9
+ # Set an optional token that must be provided as a query string to retrieve
10
+ # status via HTTP.
11
+ #secret_token: il1k3tUr7l3z
12
12
 
13
- ### Specify paths containing custom modules to load, relative to this file.
13
+ # Specify paths containing custom modules to load, relative to this file.
14
14
  module_paths:
15
15
  - modules
16
16
 
17
- ### List all modules to be monitored.
17
+ # List all modules to run.
18
18
  modules:
19
- - custom_module
20
- #- disk
21
- #- processes
22
- #- unicorn
23
- #- what
24
- #- existence
25
-
26
- ### Pass parameters into modules.
27
- module_config:
28
- custom_module:
19
+ - name: unicorn
20
+ type: unicorn
21
+ config:
22
+ warning: 1
23
+ alert: 0
24
+ - name: hello world
25
+ type: custom_module
26
+ config:
27
+ hello: hello
28
+ world: world
29
+ - name: world hello
30
+ type: custom_module
31
+ config:
29
32
  hello: world
30
33
  world: hello
31
- # disk:
32
- # # percentage of disk space filled
33
- # "/$":
34
- # warning: 70%
35
- # alert: 80%
36
- # "/Volumes/BOOTCAMP":
37
- # warning: 80%
38
- # alert: 90%
39
- # processes:
40
- # postgres: postgres
41
- # beanstalkd: beanstalkd
42
- # redis: redis-server
43
- # unicorn:
44
- # # minimum number of workers before warning and alert statuses
45
- # warning: 1
46
- # alert: 0
47
- # what:
48
- # some_host: somehost.com
49
- # existence:
34
+ #- name: Macintosh HD
35
+ # type: disk
36
+ #- name: Boot Camp
37
+ # type: disk
38
+ # config:
39
+ # regexp: "/Volumes/BOOTCAMP"
40
+ #- name: postgres
41
+ # type: process
42
+ #- name: beanstalk
43
+ # type: process
44
+ # config:
45
+ # regexp: beanstalkd
46
+ #- name: redis
47
+ # type: process
48
+ # config:
49
+ # regexp: redis-server
50
+ #- type: existence
51
+ # config:
50
52
  # paths:
51
- # - /mnt/a_drive
53
+ # - /mnt/a_drive
54
+ #- type: what
55
+ # config:
56
+ # some_host: somehost.com
52
57
 
53
- ### Specify any other config files to load.
54
- # configs:
55
- # - more_config/stuff.yml
58
+ # Specify any other config files to load.
59
+ #configs:
60
+ #- more_config/stuff.yml
data/lib/what/config.rb CHANGED
@@ -5,8 +5,7 @@ module What
5
5
  'formatter' => 'json',
6
6
  'configs' => [],
7
7
  'module_paths' => [],
8
- 'modules' => [],
9
- 'module_config' => {}
8
+ 'modules' => []
10
9
  }
11
10
 
12
11
  @config = {}
@@ -1,11 +1,14 @@
1
1
  module What
2
2
  class Modules::Base
3
- def initialize
4
- @config = if defined?(DEFAULTS)
5
- DEFAULTS.merge(Config['module_config'][self.name] || {})
6
- else
7
- Config['module_config'][self.name]
8
- end
3
+ def initialize(params={})
4
+ defaults = (self.class)::DEFAULTS rescue {}
5
+ @name = params['name']
6
+ @config = defaults.merge(params['config'] || {})
7
+ @max = params['max'] || 'alert'
8
+ initialize_module
9
+ end
10
+
11
+ def initialize_module
9
12
  end
10
13
 
11
14
  def name
@@ -16,7 +19,18 @@ module What
16
19
  end
17
20
 
18
21
  def status
19
- {'health' => health}.merge(details)
22
+ status = {}
23
+ status['name'] = @name if @name
24
+ status['type'] = name # FIXME
25
+ status['health'] = if @max == 'ok' || health == 'ok'
26
+ 'ok'
27
+ elsif @max == 'warning' || health == 'warning'
28
+ 'warning'
29
+ else
30
+ 'alert'
31
+ end
32
+ status['details'] = details
33
+ status
20
34
  end
21
35
 
22
36
  def health
@@ -1,60 +1,45 @@
1
1
  module What
2
2
  class Modules::Disk < Modules::Base
3
- def initialize
4
- super
5
- @config.each do |name, config|
6
- if config.is_a?(Hash)
7
- @config[name] = {
8
- 'warning' => config['warning'].to_i,
9
- 'alert' => config['alert'].to_i
10
- }
11
- else
12
- @config[name] = {
13
- 'warning' => config.to_i,
14
- 'alert' => 100
15
- }
16
- end
17
- end
18
- @drives = {}
3
+ DEFAULTS = {
4
+ 'regexp' => '/$',
5
+ 'warning' => '90%',
6
+ 'alert' => '99%'
7
+ }
8
+
9
+ def initialize_module
10
+ @regexp = Regexp.new(@config['regexp'])
19
11
  end
20
12
 
21
13
  def check!
22
- @config.each do |name, config|
23
- ln = `df -h`.split("\n").grep(Regexp.new(name)).first
24
- if ln
25
- fields = ln.split(/\s+/)
26
- @drives[name] = {
27
- 'size' => fields[1],
28
- 'used' => fields[2],
29
- 'avail' => fields[3],
30
- 'use%' => fields[4].to_i,
31
- 'warning%' => config['warning'],
32
- 'alert%' => config['alert']
33
- }
34
- else
35
- @drives[name] = nil
36
- end
37
- end
14
+ line = `df -h`.split("\n").grep(@regexp).first
15
+ @info = if line
16
+ fields = line.split(/\s+/)
17
+ {
18
+ 'size' => fields[1],
19
+ 'used' => fields[2],
20
+ 'avail' => fields[3],
21
+ 'use%' => fields[4].to_i,
22
+ 'warning%' => @config['warning'].to_i,
23
+ 'alert%' => @config['alert'].to_i,
24
+ 'regexp' => @config['regexp']
25
+ }
26
+ end
38
27
  end
39
28
 
40
29
  def health
41
- healths = @drives.map do |name, attrs|
42
- puts name, attrs.inspect
43
- if attrs.nil?
44
- 'alert'
45
- elsif attrs['use%'] >= attrs['alert%']
46
- 'alert'
47
- elsif attrs['use%'] >= attrs['warning%']
48
- 'warning'
49
- else
50
- 'ok'
51
- end
52
- end
53
- Helpers.overall_health(healths)
30
+ if @info.nil?
31
+ 'alert'
32
+ elsif @info['use%'] >= @info['alert%']
33
+ 'alert'
34
+ elsif @info['use%'] >= @info['warning%']
35
+ 'warning'
36
+ else
37
+ 'ok'
38
+ end
54
39
  end
55
40
 
56
41
  def details
57
- @drives
42
+ @info
58
43
  end
59
44
  end
60
45
  end
@@ -4,8 +4,7 @@ module What
4
4
  'paths' => []
5
5
  }
6
6
 
7
- def initialize
8
- super
7
+ def initialize_module
9
8
  @paths = {}
10
9
  end
11
10
 
@@ -0,0 +1,27 @@
1
+ module What
2
+ class Modules::Process < Modules::Base
3
+ def initialize_module
4
+ @regexp = Regexp.new(@config['regexp'] || @name)
5
+ @processes = []
6
+ end
7
+
8
+ def check!
9
+ @processes = `ps aux`.split("\n").grep(@regexp).map do |ln|
10
+ ln =~ /^\w+\s+(\d+).*(\d+:\d\d(?:\.\d\d)?) (.*)$/
11
+ {'pid' => $1, 'cpu_time' => $2, 'proctitle' => $3.strip}
12
+ end
13
+ end
14
+
15
+ def health
16
+ if @processes.count > 0
17
+ 'ok'
18
+ else
19
+ 'alert'
20
+ end
21
+ end
22
+
23
+ def details
24
+ {'processes' => @processes}
25
+ end
26
+ end
27
+ end
@@ -5,8 +5,7 @@ module What
5
5
  'alert' => 0
6
6
  }
7
7
 
8
- def initialize
9
- super
8
+ def initialize_module
10
9
  @unicorns = []
11
10
  end
12
11
 
@@ -1,8 +1,7 @@
1
1
  # This module assumes the other servers are using the JSON formatter.
2
2
  module What
3
3
  class Modules::What < Modules::Base
4
- def initialize
5
- super
4
+ def initialize_module
6
5
  @config.each do |name, host|
7
6
  @config[name] = "http://#{host}:9428"
8
7
  end
data/lib/what/monitor.rb CHANGED
@@ -2,9 +2,9 @@ module What
2
2
  class Monitor
3
3
  # don't worry, these method names are ironic
4
4
  def self.go!
5
- @modules = Config['modules'].map do |m|
6
- name = Helpers.camelize(m)
7
- Modules.const_get(name).new
5
+ @modules = Config['modules'].map do |mod|
6
+ name = Helpers.camelize(mod.delete('type'))
7
+ Modules.const_get(name).new(mod)
8
8
  end
9
9
 
10
10
  Thread.abort_on_exception = true
@@ -12,14 +12,17 @@ module What
12
12
  end
13
13
 
14
14
  def self.do_it(modules)
15
+ Status['details'] = []
15
16
  loop do
17
+ statuses = []
16
18
  healths = []
17
19
  modules.each do |mod|
18
20
  mod.check!
19
- healths << mod.health
20
- Status[mod.name] = mod.status
21
+ healths << mod.status['health']
22
+ statuses << mod.status
21
23
  end
22
24
  Status['health'] = Helpers.overall_health(healths)
25
+ Status['details'] = statuses
23
26
  sleep Config['interval']
24
27
  end
25
28
  end
data/lib/what/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module What
2
- VERSION = "0.0.16"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: what
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 16
10
- version: 0.0.16
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Fitzgerald
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-05-20 00:00:00 -07:00
19
+ date: 2011-06-01 00:00:00 -07:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -100,7 +100,7 @@ files:
100
100
  - lib/what/modules/base.rb
101
101
  - lib/what/modules/disk.rb
102
102
  - lib/what/modules/existence.rb
103
- - lib/what/modules/processes.rb
103
+ - lib/what/modules/process.rb
104
104
  - lib/what/modules/unicorn.rb
105
105
  - lib/what/modules/what.rb
106
106
  - lib/what/monitor.rb
@@ -1,34 +0,0 @@
1
- module What
2
- class Modules::Processes < Modules::Base
3
- def initialize
4
- super
5
- @config.each do |name, regexp_str|
6
- @config[name] = Regexp.new(regexp_str)
7
- end
8
- @processes = {}
9
- end
10
-
11
- def check!
12
- @config.each do |name, regexp|
13
- @processes[name] = `ps aux`.split("\n").grep(regexp).map do |ln|
14
- ln =~ /^\w+\s+(\d+).*(\d+:\d\d(?:\.\d\d)?) (.*)$/
15
- {'pid' => $1, 'cpu_time' => $2, 'proctitle' => $3.strip}
16
- end
17
- end
18
- end
19
-
20
- def health
21
- all_ok = true
22
- @processes.each do |name, results|
23
- if results.count == 0
24
- all_ok = false
25
- end
26
- end
27
- all_ok ? 'ok' : 'alert'
28
- end
29
-
30
- def details
31
- @processes
32
- end
33
- end
34
- end