what 0.0.10 → 0.0.11

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.
@@ -27,13 +27,13 @@ class What::Modules::CustomModule < What::Modules::Base
27
27
  # The health and details methods are called whenever the server receives
28
28
  # an HTTP request.
29
29
 
30
- # health should return one of the following symbols:
31
- # :ok Everything's fine.
32
- # :warning There's a problem, but it's not critical.
33
- # :alert I need to get out of bed to fix this.
30
+ # health should return one of the following strings:
31
+ # 'ok' Everything's fine.
32
+ # 'warning' There's a problem, but it's not critical.
33
+ # 'alert' I need to get out of bed to fix this.
34
34
  # (mandatory)
35
35
  def health
36
- :ok
36
+ 'ok'
37
37
  end
38
38
 
39
39
  # details can return a hash containing any additional information
@@ -47,6 +47,6 @@ class What::Modules::CustomModule < What::Modules::Base
47
47
  @hellos.times do
48
48
  greeting << @config['world']
49
49
  end
50
- {:greeting => greeting.join(' ') + '!'}
50
+ {'greeting' => greeting.join(' ') + '!'}
51
51
  end
52
52
  end
data/example/what.yml CHANGED
@@ -4,7 +4,7 @@
4
4
  formatter: json
5
5
 
6
6
  ### Set the polling interval for all services, in seconds. (default: 10)
7
- # interval: 10
7
+ interval: 10
8
8
 
9
9
  ### Specify paths containing custom modules to load, relative to this file.
10
10
  module_paths:
@@ -16,6 +16,7 @@ modules:
16
16
  #- processes
17
17
  #- unicorn
18
18
  #- what
19
+ #- existence
19
20
 
20
21
  ### Pass parameters into modules.
21
22
  module_config:
@@ -31,7 +32,10 @@ module_config:
31
32
  # warning: 1
32
33
  # alert: 0
33
34
  # what:
34
- # some_server: server.com
35
+ # some_host: somehost.com
36
+ # existence:
37
+ # paths:
38
+ # - /mnt/a_drive
35
39
 
36
40
  ### Specify any other config files to load.
37
41
  # configs:
data/lib/what/helpers.rb CHANGED
@@ -3,14 +3,14 @@ module What
3
3
  # Take an array of healths and determine overall health, on
4
4
  # the principle that overall health == the worst sub-health.
5
5
  def self.overall_health(healths)
6
- healths.reduce(:ok) do |overall, current|
6
+ healths.reduce('ok') do |overall, current|
7
7
  case current
8
- when :ok
8
+ when 'ok'
9
9
  overall
10
- when :warning
11
- :warning if overall != :alert
10
+ when 'warning'
11
+ 'warning' if overall != 'alert'
12
12
  else
13
- :alert
13
+ 'alert'
14
14
  end
15
15
  end
16
16
  end
@@ -16,7 +16,7 @@ module What
16
16
  end
17
17
 
18
18
  def status
19
- { :health => health }.merge(details)
19
+ {'health' => health}.merge(details)
20
20
  end
21
21
 
22
22
  def health
@@ -0,0 +1,30 @@
1
+ module What
2
+ class Modules::Existence < Modules::Base
3
+ DEFAULTS = {
4
+ 'paths' => []
5
+ }
6
+
7
+ def initialize
8
+ super
9
+ @paths = {}
10
+ end
11
+
12
+ def check!
13
+ @config['paths'].each do |path|
14
+ if Dir[path].count == 0
15
+ @paths[path] = false
16
+ else
17
+ @paths[path] = true
18
+ end
19
+ end
20
+ end
21
+
22
+ def health
23
+ Helpers.overall_health(@paths.map { |k, v| v ? 'ok' : 'alert' })
24
+ end
25
+
26
+ def details
27
+ @paths
28
+ end
29
+ end
30
+ end
@@ -12,7 +12,7 @@ module What
12
12
  @config.each do |name, regexp|
13
13
  @processes[name] = `ps aux`.split("\n").grep(regexp).map do |ln|
14
14
  ln =~ /^\w+\s+(\d+).*(\d+:\d\d(?:\.\d\d)?) (.*)$/
15
- {:pid => $1, :cpu_time => $2, :proctitle => $3.strip}
15
+ {'pid' => $1, 'cpu_time' => $2, 'proctitle' => $3.strip}
16
16
  end
17
17
  end
18
18
  end
@@ -24,7 +24,7 @@ module What
24
24
  all_ok = false
25
25
  end
26
26
  end
27
- all_ok ? :ok : :alert
27
+ all_ok ? 'ok' : 'alert'
28
28
  end
29
29
 
30
30
  def details
@@ -13,22 +13,22 @@ module What
13
13
  def check!
14
14
  @unicorns = `ps aux`.split("\n").grep(/unicorn_rails worker/).map do |ln|
15
15
  ln =~ /^\w+\s+(\d+).*(\d+:\d\d(?:\.\d\d)?) unicorn/
16
- {:pid => $1, :cpu_time => $2}
16
+ {'pid' => $1, 'cpu_time' => $2}
17
17
  end
18
18
  end
19
19
 
20
20
  def health
21
21
  if @unicorns.count > @config['warning']
22
- :ok
22
+ 'ok'
23
23
  elsif @unicorns.count > @config['alert']
24
- :warning
24
+ 'warning'
25
25
  else
26
- :alert
26
+ 'alert'
27
27
  end
28
28
  end
29
29
 
30
30
  def details
31
- {:workers => @unicorns.count, :details => @unicorns}
31
+ {'workers' => @unicorns.count, 'details' => @unicorns}
32
32
  end
33
33
  end
34
34
  end
@@ -16,7 +16,7 @@ module What
16
16
  end
17
17
 
18
18
  def health
19
- Helpers.overall_health(@whats.map { |_, attrs| attrs[:health] })
19
+ Helpers.overall_health(@whats.map { |_, attrs| attrs['health'] })
20
20
  end
21
21
 
22
22
  def details
data/lib/what/monitor.rb CHANGED
@@ -19,7 +19,7 @@ module What
19
19
  healths << mod.health
20
20
  Status[mod.name] = mod.status
21
21
  end
22
- Status[:health] = Helpers.overall_health(healths)
22
+ Status['health'] = Helpers.overall_health(healths)
23
23
  sleep Config['interval']
24
24
  end
25
25
  end
data/lib/what/server.rb CHANGED
@@ -8,7 +8,7 @@ module What
8
8
 
9
9
  def call(_)
10
10
  [
11
- Status[:health] != :alert ? 200 : 503,
11
+ Status['health'] != 'alert' ? 200 : 503,
12
12
  {'Content-Type' => Formatter.mime},
13
13
  Formatter.format(Status.all)
14
14
  ]
data/lib/what/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module What
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
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: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 10
10
- version: 0.0.10
9
+ - 11
10
+ version: 0.0.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Lower
@@ -91,6 +91,7 @@ files:
91
91
  - lib/what/helpers.rb
92
92
  - lib/what/modules.rb
93
93
  - lib/what/modules/base.rb
94
+ - lib/what/modules/existence.rb
94
95
  - lib/what/modules/processes.rb
95
96
  - lib/what/modules/unicorn.rb
96
97
  - lib/what/modules/what.rb