what 0.0.16 → 0.1.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/example/modules/custom_module.rb +3 -5
- data/example/what.yml +47 -42
- data/lib/what/config.rb +1 -2
- data/lib/what/modules/base.rb +21 -7
- data/lib/what/modules/disk.rb +31 -46
- data/lib/what/modules/existence.rb +1 -2
- data/lib/what/modules/process.rb +27 -0
- data/lib/what/modules/unicorn.rb +1 -2
- data/lib/what/modules/what.rb +1 -2
- data/lib/what/monitor.rb +8 -5
- data/lib/what/version.rb +1 -1
- metadata +5 -5
- data/lib/what/modules/processes.rb +0 -34
@@ -8,12 +8,10 @@ class What::Modules::CustomModule < What::Modules::Base
|
|
8
8
|
'world' => 'world'
|
9
9
|
}
|
10
10
|
|
11
|
-
# You can use the
|
12
|
-
#
|
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
|
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
|
-
|
4
|
-
formatter: json
|
3
|
+
# Choose between JSON and YAML formatting.
|
4
|
+
#formatter: json
|
5
5
|
|
6
|
-
|
7
|
-
interval: 10
|
6
|
+
# Set the polling interval for all services, in seconds.
|
7
|
+
#interval: 10
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
#
|
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
|
-
|
13
|
+
# Specify paths containing custom modules to load, relative to this file.
|
14
14
|
module_paths:
|
15
15
|
- modules
|
16
16
|
|
17
|
-
|
17
|
+
# List all modules to run.
|
18
18
|
modules:
|
19
|
-
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
32
|
-
#
|
33
|
-
|
34
|
-
#
|
35
|
-
#
|
36
|
-
# "/Volumes/BOOTCAMP"
|
37
|
-
|
38
|
-
#
|
39
|
-
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
|
48
|
-
#
|
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
|
-
#
|
53
|
+
# - /mnt/a_drive
|
54
|
+
#- type: what
|
55
|
+
# config:
|
56
|
+
# some_host: somehost.com
|
52
57
|
|
53
|
-
|
54
|
-
#
|
55
|
-
|
58
|
+
# Specify any other config files to load.
|
59
|
+
#configs:
|
60
|
+
#- more_config/stuff.yml
|
data/lib/what/config.rb
CHANGED
data/lib/what/modules/base.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
module What
|
2
2
|
class Modules::Base
|
3
|
-
def initialize
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
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
|
data/lib/what/modules/disk.rb
CHANGED
@@ -1,60 +1,45 @@
|
|
1
1
|
module What
|
2
2
|
class Modules::Disk < Modules::Base
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
@
|
42
|
+
@info
|
58
43
|
end
|
59
44
|
end
|
60
45
|
end
|
@@ -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
|
data/lib/what/modules/unicorn.rb
CHANGED
data/lib/what/modules/what.rb
CHANGED
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 |
|
6
|
-
name = Helpers.camelize(
|
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
|
-
|
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
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: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
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-
|
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/
|
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
|