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.
- data/example/modules/custom_module.rb +6 -6
- data/example/what.yml +6 -2
- data/lib/what/helpers.rb +5 -5
- data/lib/what/modules/base.rb +1 -1
- data/lib/what/modules/existence.rb +30 -0
- data/lib/what/modules/processes.rb +2 -2
- data/lib/what/modules/unicorn.rb +5 -5
- data/lib/what/modules/what.rb +1 -1
- data/lib/what/monitor.rb +1 -1
- data/lib/what/server.rb +1 -1
- data/lib/what/version.rb +1 -1
- metadata +4 -3
@@ -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
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
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
|
-
|
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
|
-
{
|
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
|
-
|
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
|
-
#
|
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(
|
6
|
+
healths.reduce('ok') do |overall, current|
|
7
7
|
case current
|
8
|
-
when
|
8
|
+
when 'ok'
|
9
9
|
overall
|
10
|
-
when
|
11
|
-
|
10
|
+
when 'warning'
|
11
|
+
'warning' if overall != 'alert'
|
12
12
|
else
|
13
|
-
|
13
|
+
'alert'
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/lib/what/modules/base.rb
CHANGED
@@ -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
|
-
{
|
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 ?
|
27
|
+
all_ok ? 'ok' : 'alert'
|
28
28
|
end
|
29
29
|
|
30
30
|
def details
|
data/lib/what/modules/unicorn.rb
CHANGED
@@ -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
|
-
{
|
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
|
-
|
22
|
+
'ok'
|
23
23
|
elsif @unicorns.count > @config['alert']
|
24
|
-
|
24
|
+
'warning'
|
25
25
|
else
|
26
|
-
|
26
|
+
'alert'
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
def details
|
31
|
-
{
|
31
|
+
{'workers' => @unicorns.count, 'details' => @unicorns}
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
data/lib/what/modules/what.rb
CHANGED
data/lib/what/monitor.rb
CHANGED
data/lib/what/server.rb
CHANGED
data/lib/what/version.rb
CHANGED
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:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
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
|