check_passenger 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +24 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +29 -0
- data/Rakefile +8 -0
- data/TODO.md +12 -0
- data/bin/check_passenger +101 -0
- data/check_passenger.gemspec +29 -0
- data/lib/check_passenger.rb +13 -0
- data/lib/check_passenger/check.rb +96 -0
- data/lib/check_passenger/nagios_check.rb +66 -0
- data/lib/check_passenger/parser.rb +120 -0
- data/lib/check_passenger/passenger_status.rb +29 -0
- data/lib/check_passenger/status_output_error.rb +10 -0
- data/lib/check_passenger/version.rb +3 -0
- data/test/passenger-status +82 -0
- data/test/sample_output_1.txt +76 -0
- data/test/sample_output_2.txt +64 -0
- data/test/test_check.rb +122 -0
- data/test/test_helper.rb +9 -0
- data/test/test_nagios_check.rb +72 -0
- data/test/test_parser.rb +166 -0
- data/test/test_passenger_status.rb +32 -0
- metadata +158 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
module CheckPassenger
|
2
|
+
class PassengerStatus
|
3
|
+
class << self
|
4
|
+
attr_accessor :path
|
5
|
+
|
6
|
+
def run
|
7
|
+
`#{passenger_status_executable_path}`
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def passenger_status_executable_path
|
13
|
+
command = if @path and File.exist?(@path)
|
14
|
+
if File.directory?(@path)
|
15
|
+
File.expand_path('passenger-status', @path)
|
16
|
+
else
|
17
|
+
@path
|
18
|
+
end
|
19
|
+
else
|
20
|
+
`which passenger-status`.strip
|
21
|
+
end
|
22
|
+
|
23
|
+
raise Errno::ENOENT, 'Cannot find passenger-status' unless File.executable?(command)
|
24
|
+
|
25
|
+
command
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
puts DATA.read
|
4
|
+
|
5
|
+
__END__
|
6
|
+
Version : 4.0.46
|
7
|
+
Date : 2014-09-11 00:57:57 +0200
|
8
|
+
Instance: 32028
|
9
|
+
----------- General information -----------
|
10
|
+
Max pool size : 40
|
11
|
+
Processes : 26
|
12
|
+
Requests in top-level queue : 0
|
13
|
+
|
14
|
+
----------- Application groups -----------
|
15
|
+
/home/application_1/Site#default:
|
16
|
+
App root: /home/application_1/Site
|
17
|
+
Requests in queue: 0
|
18
|
+
* PID: 12396 Sessions: 0 Processed: 13322 Uptime: 19h 12m 52s
|
19
|
+
CPU: 0% Memory : 153M Last used: 51m 29s
|
20
|
+
* PID: 12404 Sessions: 0 Processed: 11694 Uptime: 19h 12m 52s
|
21
|
+
CPU: 0% Memory : 152M Last used: 27s ago
|
22
|
+
* PID: 12411 Sessions: 0 Processed: 2487 Uptime: 19h 12m 52s
|
23
|
+
CPU: 0% Memory : 128M Last used: 5m 56s
|
24
|
+
* PID: 12418 Sessions: 0 Processed: 16516 Uptime: 19h 12m 52s
|
25
|
+
CPU: 1% Memory : 159M Last used: 51m 29s
|
26
|
+
* PID: 12425 Sessions: 0 Processed: 9004 Uptime: 19h 12m 52s
|
27
|
+
CPU: 0% Memory : 150M Last used: 5m 56s
|
28
|
+
* PID: 12432 Sessions: 0 Processed: 9733 Uptime: 19h 12m 52s
|
29
|
+
CPU: 0% Memory : 137M Last used: 50m 37s
|
30
|
+
* PID: 12439 Sessions: 0 Processed: 15867 Uptime: 19h 12m 52s
|
31
|
+
CPU: 1% Memory : 269M Last used: 51m 29s
|
32
|
+
* PID: 12450 Sessions: 0 Processed: 21723 Uptime: 19h 12m 52s
|
33
|
+
CPU: 1% Memory : 172M Last used: 50m 37s
|
34
|
+
* PID: 12457 Sessions: 0 Processed: 27773 Uptime: 19h 12m 52s
|
35
|
+
CPU: 2% Memory : 183M Last used: 1s ago
|
36
|
+
* PID: 12464 Sessions: 0 Processed: 25461 Uptime: 19h 12m 52s
|
37
|
+
CPU: 1% Memory : 169M Last used: 50m 37s
|
38
|
+
* PID: 24260 Sessions: 0 Processed: 13129 Uptime: 7h 26m 53s
|
39
|
+
CPU: 2% Memory : 179M Last used: 12m 0s a
|
40
|
+
* PID: 27767 Sessions: 0 Processed: 3383 Uptime: 1h 3m 8s
|
41
|
+
CPU: 5% Memory : 157M Last used: 1s ago
|
42
|
+
|
43
|
+
/home/application_2/Site#default:
|
44
|
+
App root: /home/application_2/Site
|
45
|
+
Requests in queue: 0
|
46
|
+
* PID: 26712 Sessions: 0 Processed: 184 Uptime: 21h 36m 36s
|
47
|
+
CPU: 0% Memory : 26M Last used: 1m 11s
|
48
|
+
* PID: 26721 Sessions: 0 Processed: 0 Uptime: 21h 36m 35s
|
49
|
+
CPU: 0% Memory : 13M Last used: 21h 36m
|
50
|
+
* PID: 26728 Sessions: 0 Processed: 0 Uptime: 21h 36m 35s
|
51
|
+
CPU: 0% Memory : 13M Last used: 21h 36m
|
52
|
+
* PID: 26736 Sessions: 0 Processed: 0 Uptime: 21h 36m 35s
|
53
|
+
CPU: 0% Memory : 13M Last used: 21h 36m
|
54
|
+
|
55
|
+
/home/application_3/Site#default:
|
56
|
+
App root: /home/application_3/Site
|
57
|
+
Requests in queue: 0
|
58
|
+
* PID: 17507 Sessions: 0 Processed: 2141 Uptime: 21h 43m 33s
|
59
|
+
CPU: 0% Memory : 242M Last used: 5h 51m
|
60
|
+
* PID: 17514 Sessions: 0 Processed: 5967 Uptime: 21h 43m 33s
|
61
|
+
CPU: 0% Memory : 703M Last used: 29s ago
|
62
|
+
* PID: 17527 Sessions: 0 Processed: 6859 Uptime: 21h 43m 33s
|
63
|
+
CPU: 0% Memory : 790M Last used: 18m 23s
|
64
|
+
* PID: 17534 Sessions: 0 Processed: 4646 Uptime: 21h 43m 33s
|
65
|
+
CPU: 0% Memory : 561M Last used: 5h 51m
|
66
|
+
* PID: 17541 Sessions: 0 Processed: 3030 Uptime: 21h 43m 33s
|
67
|
+
CPU: 0% Memory : 401M Last used: 12m 15s
|
68
|
+
* PID: 17548 Sessions: 0 Processed: 1277 Uptime: 21h 43m 33s
|
69
|
+
CPU: 0% Memory : 240M Last used: 5h 51m
|
70
|
+
|
71
|
+
/home/application_4/Site#default:
|
72
|
+
App root: /home/application_4/Site
|
73
|
+
Requests in queue: 0
|
74
|
+
* PID: 32383 Sessions: 0 Processed: 2182 Uptime: 2h 7m 9s
|
75
|
+
CPU: 0% Memory : 76M Last used: 2s ago
|
76
|
+
* PID: 23605 Sessions: 0 Processed: 609 Uptime: 1h 7m 25s
|
77
|
+
CPU: 0% Memory : 61M Last used: 1m 7s ago
|
78
|
+
* PID: 13173 Sessions: 0 Processed: 417 Uptime: 44m 7s
|
79
|
+
CPU: 0% Memory : 60M Last used: 1m 7s ago
|
80
|
+
* PID: 24379 Sessions: 0 Processed: 275 Uptime: 32m 7s
|
81
|
+
CPU: 0% Memory : 59M Last used: 0s ago
|
82
|
+
|
@@ -0,0 +1,76 @@
|
|
1
|
+
Version : 4.0.46
|
2
|
+
Date : 2014-09-11 00:57:57 +0200
|
3
|
+
Instance: 32028
|
4
|
+
----------- General information -----------
|
5
|
+
Max pool size : 40
|
6
|
+
Processes : 26
|
7
|
+
Requests in top-level queue : 0
|
8
|
+
|
9
|
+
----------- Application groups -----------
|
10
|
+
/home/application_1/Site#default:
|
11
|
+
App root: /home/application_1/Site
|
12
|
+
Requests in queue: 0
|
13
|
+
* PID: 12396 Sessions: 0 Processed: 13322 Uptime: 19h 12m 52s
|
14
|
+
CPU: 0% Memory : 153M Last used: 51m 29s
|
15
|
+
* PID: 12404 Sessions: 0 Processed: 11694 Uptime: 19h 12m 52s
|
16
|
+
CPU: 0% Memory : 152M Last used: 27s ago
|
17
|
+
* PID: 12411 Sessions: 0 Processed: 2487 Uptime: 19h 12m 52s
|
18
|
+
CPU: 0% Memory : 128M Last used: 5m 56s
|
19
|
+
* PID: 12418 Sessions: 0 Processed: 16516 Uptime: 19h 12m 52s
|
20
|
+
CPU: 1% Memory : 159M Last used: 51m 29s
|
21
|
+
* PID: 12425 Sessions: 0 Processed: 9004 Uptime: 19h 12m 52s
|
22
|
+
CPU: 0% Memory : 150M Last used: 5m 56s
|
23
|
+
* PID: 12432 Sessions: 0 Processed: 9733 Uptime: 19h 12m 52s
|
24
|
+
CPU: 0% Memory : 137M Last used: 50m 37s
|
25
|
+
* PID: 12439 Sessions: 0 Processed: 15867 Uptime: 19h 12m 52s
|
26
|
+
CPU: 1% Memory : 269M Last used: 51m 29s
|
27
|
+
* PID: 12450 Sessions: 0 Processed: 21723 Uptime: 19h 12m 52s
|
28
|
+
CPU: 1% Memory : 172M Last used: 50m 37s
|
29
|
+
* PID: 12457 Sessions: 0 Processed: 27773 Uptime: 19h 12m 52s
|
30
|
+
CPU: 2% Memory : 183M Last used: 1s ago
|
31
|
+
* PID: 12464 Sessions: 0 Processed: 25461 Uptime: 19h 12m 52s
|
32
|
+
CPU: 1% Memory : 169M Last used: 50m 37s
|
33
|
+
* PID: 24260 Sessions: 0 Processed: 13129 Uptime: 7h 26m 53s
|
34
|
+
CPU: 2% Memory : 179M Last used: 12m 0s a
|
35
|
+
* PID: 27767 Sessions: 0 Processed: 3383 Uptime: 1h 3m 8s
|
36
|
+
CPU: 5% Memory : 157M Last used: 1s ago
|
37
|
+
|
38
|
+
/home/application_2/Site#default:
|
39
|
+
App root: /home/application_2/Site
|
40
|
+
Requests in queue: 0
|
41
|
+
* PID: 26712 Sessions: 0 Processed: 184 Uptime: 21h 36m 36s
|
42
|
+
CPU: 0% Memory : 26M Last used: 1m 11s
|
43
|
+
* PID: 26721 Sessions: 0 Processed: 0 Uptime: 21h 36m 35s
|
44
|
+
CPU: 0% Memory : 13M Last used: 21h 36m
|
45
|
+
* PID: 26728 Sessions: 0 Processed: 0 Uptime: 21h 36m 35s
|
46
|
+
CPU: 0% Memory : 13M Last used: 21h 36m
|
47
|
+
* PID: 26736 Sessions: 0 Processed: 0 Uptime: 21h 36m 35s
|
48
|
+
CPU: 0% Memory : 13M Last used: 21h 36m
|
49
|
+
|
50
|
+
/home/application_3/Site#default:
|
51
|
+
App root: /home/application_3/Site
|
52
|
+
Requests in queue: 0
|
53
|
+
* PID: 17507 Sessions: 0 Processed: 2141 Uptime: 21h 43m 33s
|
54
|
+
CPU: 0% Memory : 242M Last used: 5h 51m
|
55
|
+
* PID: 17514 Sessions: 0 Processed: 5967 Uptime: 21h 43m 33s
|
56
|
+
CPU: 0% Memory : 703M Last used: 29s ago
|
57
|
+
* PID: 17527 Sessions: 0 Processed: 6859 Uptime: 21h 43m 33s
|
58
|
+
CPU: 0% Memory : 790M Last used: 18m 23s
|
59
|
+
* PID: 17534 Sessions: 0 Processed: 4646 Uptime: 21h 43m 33s
|
60
|
+
CPU: 0% Memory : 561M Last used: 5h 51m
|
61
|
+
* PID: 17541 Sessions: 0 Processed: 3030 Uptime: 21h 43m 33s
|
62
|
+
CPU: 0% Memory : 401M Last used: 12m 15s
|
63
|
+
* PID: 17548 Sessions: 0 Processed: 1277 Uptime: 21h 43m 33s
|
64
|
+
CPU: 0% Memory : 240M Last used: 5h 51m
|
65
|
+
|
66
|
+
/home/application_4/Site#default:
|
67
|
+
App root: /home/application_4/Site
|
68
|
+
Requests in queue: 0
|
69
|
+
* PID: 32383 Sessions: 0 Processed: 2182 Uptime: 2h 7m 9s
|
70
|
+
CPU: 0% Memory : 76M Last used: 2s ago
|
71
|
+
* PID: 23605 Sessions: 0 Processed: 609 Uptime: 1h 7m 25s
|
72
|
+
CPU: 0% Memory : 61M Last used: 1m 7s ago
|
73
|
+
* PID: 13173 Sessions: 0 Processed: 417 Uptime: 44m 7s
|
74
|
+
CPU: 0% Memory : 60M Last used: 1m 7s ago
|
75
|
+
* PID: 24379 Sessions: 0 Processed: 275 Uptime: 32m 7s
|
76
|
+
CPU: 0% Memory : 59M Last used: 0s ago
|
@@ -0,0 +1,64 @@
|
|
1
|
+
Version : 4.0.46
|
2
|
+
Date : 2014-09-10 21:24:22 -0400
|
3
|
+
Instance: 28669
|
4
|
+
----------- General information -----------
|
5
|
+
Max pool size : 40
|
6
|
+
Processes : 22
|
7
|
+
Requests in top-level queue : 0
|
8
|
+
|
9
|
+
----------- Application groups -----------
|
10
|
+
/home/application_1/Site#default:
|
11
|
+
App root: /home/application_1/Site
|
12
|
+
Requests in queue: 0
|
13
|
+
* PID: 10966 Sessions: 0 Processed: 10840 Uptime: 15h 39m 16s
|
14
|
+
CPU: 1% Memory : 170M Last used: 17s ago
|
15
|
+
* PID: 10974 Sessions: 0 Processed: 0 Uptime: 15h 39m 16s
|
16
|
+
CPU: 0% Memory : 14M Last used: 15h 39m
|
17
|
+
* PID: 10981 Sessions: 0 Processed: 0 Uptime: 15h 39m 16s
|
18
|
+
CPU: 0% Memory : 14M Last used: 15h 39m
|
19
|
+
* PID: 10988 Sessions: 0 Processed: 0 Uptime: 15h 39m 16s
|
20
|
+
CPU: 0% Memory : 14M Last used: 15h 39m
|
21
|
+
* PID: 10995 Sessions: 0 Processed: 0 Uptime: 15h 39m 16s
|
22
|
+
CPU: 0% Memory : 14M Last used: 15h 39m
|
23
|
+
* PID: 11002 Sessions: 0 Processed: 0 Uptime: 15h 39m 16s
|
24
|
+
CPU: 0% Memory : 13M Last used: 15h 39m
|
25
|
+
* PID: 11009 Sessions: 0 Processed: 0 Uptime: 15h 39m 15s
|
26
|
+
CPU: 0% Memory : 13M Last used: 15h 39m
|
27
|
+
* PID: 11016 Sessions: 0 Processed: 0 Uptime: 15h 39m 15s
|
28
|
+
CPU: 0% Memory : 14M Last used: 15h 39m
|
29
|
+
* PID: 11023 Sessions: 0 Processed: 2977 Uptime: 15h 39m 15s
|
30
|
+
CPU: 0% Memory : 144M Last used: 3s ago
|
31
|
+
* PID: 11030 Sessions: 0 Processed: 12869 Uptime: 15h 39m 15s
|
32
|
+
CPU: 1% Memory : 205M Last used: 0s ago
|
33
|
+
* PID: 11037 Sessions: 0 Processed: 8255 Uptime: 15h 39m 15s
|
34
|
+
CPU: 1% Memory : 162M Last used: 46s ago
|
35
|
+
* PID: 11044 Sessions: 0 Processed: 6311 Uptime: 15h 39m 15s
|
36
|
+
CPU: 1% Memory : 177M Last used: 21m 16s
|
37
|
+
|
38
|
+
/home/application_2/Site#default:
|
39
|
+
App root: /home/application_2/Site
|
40
|
+
Requests in queue: 0
|
41
|
+
* PID: 1679 Sessions: 0 Processed: 1273 Uptime: 3d 17h 40m 10s
|
42
|
+
CPU: 0% Memory : 45M Last used: 6m 4
|
43
|
+
* PID: 1686 Sessions: 0 Processed: 0 Uptime: 3d 17h 40m 10s
|
44
|
+
CPU: 0% Memory : 13M Last used: 3d 1
|
45
|
+
* PID: 1693 Sessions: 0 Processed: 0 Uptime: 3d 17h 40m 10s
|
46
|
+
CPU: 0% Memory : 13M Last used: 3d 1
|
47
|
+
* PID: 1700 Sessions: 0 Processed: 59 Uptime: 3d 17h 40m 10s
|
48
|
+
CPU: 0% Memory : 24M Last used: 2d 2
|
49
|
+
|
50
|
+
/home/application_3/Site#default:
|
51
|
+
App root: /home/application_3/Site
|
52
|
+
Requests in queue: 0
|
53
|
+
* PID: 8170 Sessions: 0 Processed: 13179 Uptime: 1d 12h 8m 46s
|
54
|
+
CPU: 1% Memory : 612M Last used: 0s ag
|
55
|
+
* PID: 8180 Sessions: 0 Processed: 20043 Uptime: 1d 12h 8m 45s
|
56
|
+
CPU: 1% Memory : 663M Last used: 11h 3
|
57
|
+
* PID: 8190 Sessions: 0 Processed: 13395 Uptime: 1d 12h 8m 45s
|
58
|
+
CPU: 1% Memory : 324M Last used: 16h 5
|
59
|
+
* PID: 8200 Sessions: 0 Processed: 8310 Uptime: 1d 12h 8m 45s
|
60
|
+
CPU: 0% Memory : 414M Last used: 43s a
|
61
|
+
* PID: 8207 Sessions: 0 Processed: 8589 Uptime: 1d 12h 8m 45s
|
62
|
+
CPU: 0% Memory : 415M Last used: 2m 43
|
63
|
+
* PID: 8214 Sessions: 0 Processed: 15640 Uptime: 1d 12h 8m 45s
|
64
|
+
CPU: 1% Memory : 507M Last used: 11h 3
|
data/test/test_check.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe CheckPassenger::Check do
|
4
|
+
describe '#passenger_status' do
|
5
|
+
it 'returns a PassengerStatus class' do
|
6
|
+
assert_equal 'CheckPassenger::PassengerStatus', CheckPassenger::Check.send(:passenger_status).name
|
7
|
+
assert_equal 'CheckPassenger::PassengerStatus',
|
8
|
+
CheckPassenger::Check.send(:passenger_status, File.dirname(__FILE__)).name
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def output_data_structure_test(output_data)
|
13
|
+
assert_kind_of Array, output_data
|
14
|
+
|
15
|
+
output_data.each do |datum|
|
16
|
+
assert_kind_of Hash, datum
|
17
|
+
assert datum.has_key?(:text)
|
18
|
+
assert datum.has_key?(:counter)
|
19
|
+
assert datum.has_key?(:value)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'sample output 1' do
|
24
|
+
before do
|
25
|
+
sample_path = File.expand_path('sample_output_1.txt', File.dirname(__FILE__))
|
26
|
+
data = File.read(sample_path)
|
27
|
+
@parsed_data = CheckPassenger::Parser.new(data)
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#process_count' do
|
31
|
+
it 'reports global process count' do
|
32
|
+
options = { parsed_data: @parsed_data }
|
33
|
+
output_status, output_data = CheckPassenger::Check.process_count(options)
|
34
|
+
|
35
|
+
assert_equal :ok, output_status
|
36
|
+
output_data_structure_test(output_data)
|
37
|
+
|
38
|
+
assert_equal 'process_count', output_data.first[:counter]
|
39
|
+
assert_equal 26, output_data.first[:value]
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'reports global memory' do
|
43
|
+
options = { parsed_data: @parsed_data }
|
44
|
+
output_status, output_data = CheckPassenger::Check.memory(options)
|
45
|
+
|
46
|
+
assert :ok, output_status
|
47
|
+
output_data_structure_test(output_data)
|
48
|
+
|
49
|
+
assert_equal 'memory', output_data.first[:counter]
|
50
|
+
assert_equal 5_266, output_data.first[:value]
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'reports data for all applications' do
|
54
|
+
options = { parsed_data: @parsed_data, include_all: true }
|
55
|
+
[:process_count, :memory, :live_process_count].each do |counter|
|
56
|
+
output_status, output_data = CheckPassenger::Check.send(counter, options)
|
57
|
+
|
58
|
+
assert_equal :ok, output_status
|
59
|
+
output_data_structure_test(output_data)
|
60
|
+
|
61
|
+
assert_equal 5, output_data.size
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'reports global live process count' do
|
66
|
+
options = { parsed_data: @parsed_data }
|
67
|
+
output_status, output_data = CheckPassenger::Check.live_process_count(options)
|
68
|
+
|
69
|
+
assert :ok, output_status
|
70
|
+
output_data_structure_test(output_data)
|
71
|
+
|
72
|
+
assert_equal 'live_process_count', output_data.first[:counter]
|
73
|
+
assert_equal 9, output_data.first[:value]
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'reports application process count' do
|
77
|
+
options = { parsed_data: @parsed_data, app_name: 'application_1' }
|
78
|
+
output_status, output_data = CheckPassenger::Check.process_count(options)
|
79
|
+
|
80
|
+
assert_equal :ok, output_status
|
81
|
+
output_data_structure_test(output_data)
|
82
|
+
|
83
|
+
assert_equal 'process_count', output_data.first[:counter]
|
84
|
+
assert_equal 12, output_data.first[:value]
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'reports application memory' do
|
88
|
+
options = { parsed_data: @parsed_data, app_name: 'application_2' }
|
89
|
+
output_status, output_data = CheckPassenger::Check.memory(options)
|
90
|
+
|
91
|
+
assert_equal :ok, output_status
|
92
|
+
output_data_structure_test(output_data)
|
93
|
+
|
94
|
+
assert_equal 'memory', output_data.first[:counter]
|
95
|
+
assert_equal 65, output_data.first[:value]
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'reports application live process count' do
|
99
|
+
options = { parsed_data: @parsed_data, app_name: 'application_3' }
|
100
|
+
output_status, output_data = CheckPassenger::Check.live_process_count(options)
|
101
|
+
|
102
|
+
assert_equal :ok, output_status
|
103
|
+
output_data_structure_test(output_data)
|
104
|
+
|
105
|
+
assert_equal 'live_process_count', output_data.first[:counter]
|
106
|
+
assert_equal 1, output_data.first[:value]
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'sets a warn alert when value over threshold' do
|
110
|
+
options = { parsed_data: @parsed_data, app_name: 'application_4', warn: '150', crit: '300' }
|
111
|
+
output_status, output_data = CheckPassenger::Check.memory(options)
|
112
|
+
assert_equal :warn, output_status
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'sets a crit alert when value over threshold' do
|
116
|
+
options = { parsed_data: @parsed_data, app_name: 'application_4', warn: '75', crit: '150' }
|
117
|
+
output_status, output_data = CheckPassenger::Check.memory(options)
|
118
|
+
assert_equal :crit, output_status
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
lib = File.expand_path('../lib', File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'check_passenger'
|
5
|
+
require 'minitest'
|
6
|
+
require 'minitest/autorun'
|
7
|
+
require 'minitest/reporters'
|
8
|
+
|
9
|
+
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe CheckPassenger::NagiosCheck do
|
4
|
+
before do
|
5
|
+
@obj = Class.new do
|
6
|
+
extend CheckPassenger::NagiosCheck
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#nagios_status' do
|
11
|
+
it 'returns the correct status' do
|
12
|
+
assert_equal :ok, @obj.send(:nagios_status, 2)
|
13
|
+
assert_equal :ok, @obj.send(:nagios_status, 2, { warn: '3' })
|
14
|
+
assert_equal :warn, @obj.send(:nagios_status, 6, { warn: '5' })
|
15
|
+
assert_equal :warn, @obj.send(:nagios_status, -1, { warn: '5' })
|
16
|
+
assert_equal :crit, @obj.send(:nagios_status, 6, { warn: '5', crit: '5' })
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#number_outside_range?' do
|
21
|
+
it 'processes simple numbers' do
|
22
|
+
assert @obj.send(:'number_outside_range?', -1, '10')
|
23
|
+
refute @obj.send(:'number_outside_range?', 0, '10')
|
24
|
+
refute @obj.send(:'number_outside_range?', 10, '10')
|
25
|
+
assert @obj.send(:'number_outside_range?', 11, '10')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'processes ranges with empty ends' do
|
29
|
+
assert @obj.send(:'number_outside_range?', -1, '10:')
|
30
|
+
assert @obj.send(:'number_outside_range?', 9, '10:')
|
31
|
+
refute @obj.send(:'number_outside_range?', 10, '10:')
|
32
|
+
refute @obj.send(:'number_outside_range?', 100, '10:')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'processes ranges to inifinity' do
|
36
|
+
refute @obj.send(:'number_outside_range?', -1, '~:10')
|
37
|
+
refute @obj.send(:'number_outside_range?', 10, '~:10')
|
38
|
+
assert @obj.send(:'number_outside_range?', 11, '~:10')
|
39
|
+
assert @obj.send(:'number_outside_range?', 100, '~:10')
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'processes delimited ranges' do
|
43
|
+
assert @obj.send(:'number_outside_range?', -1, '10:20')
|
44
|
+
assert @obj.send(:'number_outside_range?', 9, '10:20')
|
45
|
+
refute @obj.send(:'number_outside_range?', 10, '10:20')
|
46
|
+
refute @obj.send(:'number_outside_range?', 15, '10:20')
|
47
|
+
refute @obj.send(:'number_outside_range?', 20, '10:20')
|
48
|
+
assert @obj.send(:'number_outside_range?', 21, '10:20')
|
49
|
+
assert @obj.send(:'number_outside_range?', 100, '10:20')
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'processes negative delimited ranges' do
|
53
|
+
refute @obj.send(:'number_outside_range?', -1, '@10:20')
|
54
|
+
refute @obj.send(:'number_outside_range?', 9, '@10:20')
|
55
|
+
assert @obj.send(:'number_outside_range?', 10, '@10:20')
|
56
|
+
assert @obj.send(:'number_outside_range?', 15, '@10:20')
|
57
|
+
assert @obj.send(:'number_outside_range?', 20, '@10:20')
|
58
|
+
refute @obj.send(:'number_outside_range?', 21, '@10:20')
|
59
|
+
refute @obj.send(:'number_outside_range?', 100, '@10:20')
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'raises an exception on unknown range' do
|
63
|
+
assert_raises ArgumentError do
|
64
|
+
@obj.send(:'number_outside_range?', 100, '&10:20')
|
65
|
+
end
|
66
|
+
|
67
|
+
assert_raises ArgumentError do
|
68
|
+
@obj.send(:'number_outside_range?', 100, ':')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|