check_passenger 1.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  module CheckPassenger
2
2
  module NagiosCheck
3
- EXIT_CODES = { ok: 0, warn: 1, crit: 2 }
3
+ EXIT_CODES = {ok: 0, warn: 1, crit: 2}
4
4
 
5
5
  private
6
6
 
@@ -21,13 +21,10 @@ module CheckPassenger
21
21
  status_text = line
22
22
  when Hash
23
23
  status_text = line[:text]
24
- perf_data << '%s=%d;%s;%s;%s;%s' % [
25
- line[:counter], line[:value],
26
- line[:warn], line[:crit],
27
- line[:min], line[:max]
28
- ]
24
+ perf_data << format('%s=%d;%s;%s;%s;%s',
25
+ line[:counter], line[:value], line[:warn], line[:crit], line[:min], line[:max])
29
26
  else
30
- raise ArgumentError
27
+ fail ArgumentError
31
28
  end
32
29
 
33
30
  if main_status.nil?
@@ -42,13 +39,13 @@ module CheckPassenger
42
39
 
43
40
  def nagios_output(status, data)
44
41
  unless [:ok, :warn, :crit].include?(status)
45
- raise ArgumentError, 'Invalid status provided: %s' % status.to_s
42
+ fail ArgumentError, "Invalid status provided: #{status}"
46
43
  end
47
44
 
48
45
  main_status, status_data, perf_data = nagios_format_output(data)
49
46
 
50
47
  if perf_data.is_a?(Array) and perf_data.any?
51
- puts '%s|%s' % [main_status, perf_data.join(' ')]
48
+ puts format('%s|%s', main_status, perf_data.join(' '))
52
49
  else
53
50
  puts main_status
54
51
  end
@@ -60,17 +57,17 @@ module CheckPassenger
60
57
  def nagios_range_to_condition(nagios_range)
61
58
  case nagios_range
62
59
  when /^(-?\d+)$/
63
- lambda { |n| !(0 .. $1.to_i).include?(n) }
60
+ ->(n) { !(0..$1.to_i).include?(n) }
64
61
  when /^(-?\d+):~?$/
65
- lambda { |n| n < $1.to_i }
62
+ ->(n) { n < $1.to_i }
66
63
  when /^~?:(-?\d+)$/
67
- lambda { |n| n > $1.to_i }
64
+ ->(n) { n > $1.to_i }
68
65
  when /^(-?\d+):(-?\d+)$/
69
- lambda { |n| !($1.to_i .. $2.to_i).include?(n) }
66
+ ->(n) { !($1.to_i..$2.to_i).include?(n) }
70
67
  when /^@(-?\d+):(-?\d+)$/
71
- lambda { |n| ($1.to_i .. $2.to_i).include?(n) }
68
+ ->(n) { ($1.to_i..$2.to_i).include?(n) }
72
69
  else
73
- raise ArgumentError, 'Cannot process Nagios range: %s' % nagios_range
70
+ fail ArgumentError, "Cannot process Nagios range: #{nagios_range}"
74
71
  end
75
72
  end
76
73
 
@@ -1,6 +1,6 @@
1
1
  module CheckPassenger
2
2
  class Parser
3
- UNIT_MULTIPLIERS = { 's' => 1, 'm' => 60, 'h' => 3_600, 'd' => 86_400 }
3
+ UNIT_MULTIPLIERS = {'s' => 1, 'm' => 60, 'h' => 3_600, 'd' => 86_400}
4
4
 
5
5
  attr_reader :max_pool_size, :passenger_status_output, :passenger_version
6
6
 
@@ -18,7 +18,7 @@ module CheckPassenger
18
18
  app_data = application_data(app_name)
19
19
  app_data[:live_process_count]
20
20
  else
21
- @application_data.inject(0) { |sum, e| sum + e[:live_process_count] }
21
+ @application_data.reduce(0) { |a, e| a + e[:live_process_count] }
22
22
  end
23
23
  end
24
24
 
@@ -27,7 +27,7 @@ module CheckPassenger
27
27
  app_data = application_data(app_name)
28
28
  app_data[:memory]
29
29
  else
30
- @application_data.inject(0) { |sum, e| sum + e[:memory] }
30
+ @application_data.reduce(0) { |a, e| a + e[:memory] }
31
31
  end
32
32
  end
33
33
 
@@ -40,15 +40,28 @@ module CheckPassenger
40
40
  end
41
41
  end
42
42
 
43
+ def request_count(app_name = nil)
44
+ if app_name
45
+ app_data = application_data(app_name)
46
+ app_data[:request_count]
47
+ else
48
+ @application_data.reduce(@top_level_request_count) { |a, e| a + e[:request_count] }
49
+ end
50
+ end
51
+
52
+ def top_level_request_count(_ = nil)
53
+ @top_level_request_count
54
+ end
55
+
43
56
  private
44
57
 
45
58
  def application_data(app_name)
46
59
  if app_name
47
60
  data = @application_data.select { |d| d[:name].include?(app_name) }
48
61
  if data.size == 0
49
- raise NoApplicationError.new('Could not find an application by "%s"' % app_name, app_name)
62
+ fail NoApplicationError.new('Application is not running', app_name)
50
63
  elsif data.size > 1
51
- raise MultipleApplicationsError.new('More than one application match "%s"' % app_name, app_name)
64
+ fail MultipleApplicationsError.new("More than one running application match '#{app_name}'", app_name)
52
65
  else
53
66
  return data.first
54
67
  end
@@ -57,18 +70,15 @@ module CheckPassenger
57
70
  end
58
71
  end
59
72
 
60
- def is_process_alive?(last_used)
73
+ def process_alive?(last_used)
61
74
  life_to_seconds(last_used) < LIVE_PROCESS_TTL_IN_SECONDS
62
75
  end
63
76
 
64
77
  def life_to_seconds(last_used)
65
- last_used.split(/\s+/).inject(0) do |sum, part|
78
+ last_used.split(/\s+/).reduce(0) do |sum, part|
66
79
  if part =~ /^(\d+)([a-z])$/
67
- unless UNIT_MULTIPLIERS.has_key?($2)
68
- raise StatusOutputError.new(
69
- 'Unknown time unit "%s" in "%s"' % [$2, last_used],
70
- passenger_status_output
71
- )
80
+ unless UNIT_MULTIPLIERS.key?($2)
81
+ fail StatusOutputError.new("Unknown time unit '#{$2}' in '#{last_used}'", passenger_status_output)
72
82
  end
73
83
  sum + $1.to_i * UNIT_MULTIPLIERS[$2]
74
84
  else
@@ -82,13 +92,17 @@ module CheckPassenger
82
92
  app_data = {}
83
93
 
84
94
  app_output =~ /App root: +([^\n]+)/
85
- raise StatusOutputError.new('Could not find app name', passenger_status_output) unless $1
95
+ fail StatusOutputError.new('Could not find app name', passenger_status_output) unless $1
86
96
  app_data[:name] = $1.strip
87
97
 
98
+ app_output =~ /Requests in queue: *(\d+)/
99
+ fail StatusOutputError.new('Could not find application queued requests', passenger_status_output) unless $1
100
+ app_data[:request_count] = $1.strip.to_i
101
+
88
102
  app_data[:process_count] = app_output.scan(/PID *: *\d+/).size
89
- app_data[:memory] = app_output.scan(/Memory *: *(\d+)M/).inject(0.0) { |s, m| s + m[0].to_f }
103
+ app_data[:memory] = app_output.scan(/Memory *: *(\d+)M/).reduce(0.0) { |a, e| a + e[0].to_f }
90
104
  app_data[:live_process_count] = (
91
- app_output.scan(/Last used *: *([^\n]+)/).select { |m| is_process_alive?(m[0]) }
105
+ app_output.scan(/Last used *: *([^\n]+)/).select { |m| process_alive?(m[0]) }
92
106
  ).size
93
107
 
94
108
  app_data
@@ -97,23 +111,27 @@ module CheckPassenger
97
111
 
98
112
  def parse_passenger_status_output
99
113
  passenger_status_output =~ /^(.*?)-+ +Application groups +-+[^\n]*\n(.*)$/m
100
- raise StatusOutputError.new('Did not find "Application groups" section', passenger_status_output) unless $1
114
+ fail StatusOutputError.new('Did not find "Application groups" section', passenger_status_output) unless $1
101
115
 
102
116
  generic_data = $1
103
117
  application_data = $2
104
118
 
105
119
  generic_data =~ /Version *: *([.\d]+)/
106
- raise StatusOutputError.new('Could not find Passenger version', passenger_status_output) unless $1
120
+ fail StatusOutputError.new('Could not find Passenger version', passenger_status_output) unless $1
107
121
  @passenger_version = $1
108
122
 
109
123
  generic_data =~ /Max pool size *: *(\d+)/
110
- raise StatusOutputError.new('Could not find max pool size', passenger_status_output) unless $1
124
+ fail StatusOutputError.new('Could not find max pool size', passenger_status_output) unless $1
111
125
  @max_pool_size = $1.to_i
112
126
 
113
127
  generic_data =~ /Processes *: *(\d+)/
114
- raise StatusOutputError.new('Could not find process count', passenger_status_output) unless $1
128
+ fail StatusOutputError.new('Could not find process count', passenger_status_output) unless $1
115
129
  @process_count = $1.to_i
116
130
 
131
+ generic_data =~ /Requests in top-level queue *: *(\d+)/
132
+ fail StatusOutputError.new('Could not find top-level queued requests', passenger_status_output) unless $1
133
+ @top_level_request_count = $1.to_i
134
+
117
135
  @application_data = parse_application_data(application_data)
118
136
  end
119
137
  end
@@ -11,16 +11,16 @@ module CheckPassenger
11
11
 
12
12
  def passenger_status_executable_path
13
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
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
22
 
23
- raise Errno::ENOENT, 'Cannot find passenger-status' unless File.executable?(command)
23
+ fail Errno::ENOENT, 'Cannot find passenger-status' unless File.executable?(command)
24
24
 
25
25
  command
26
26
  end
@@ -1,3 +1,3 @@
1
1
  module CheckPassenger
2
- VERSION = '1.0'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -1,15 +1,13 @@
1
- #!/usr/bin/env ruby
1
+ #!/bin/bash
2
2
 
3
- puts DATA.read
4
-
5
- __END__
3
+ cat <<'HEREDOC'
6
4
  Version : 4.0.46
7
5
  Date : 2014-09-11 00:57:57 +0200
8
6
  Instance: 32028
9
7
  ----------- General information -----------
10
8
  Max pool size : 40
11
9
  Processes : 26
12
- Requests in top-level queue : 0
10
+ Requests in top-level queue : 10
13
11
 
14
12
  ----------- Application groups -----------
15
13
  /home/application_1/Site#default:
@@ -42,7 +40,7 @@ Requests in top-level queue : 0
42
40
 
43
41
  /home/application_2/Site#default:
44
42
  App root: /home/application_2/Site
45
- Requests in queue: 0
43
+ Requests in queue: 2
46
44
  * PID: 26712 Sessions: 0 Processed: 184 Uptime: 21h 36m 36s
47
45
  CPU: 0% Memory : 26M Last used: 1m 11s
48
46
  * PID: 26721 Sessions: 0 Processed: 0 Uptime: 21h 36m 35s
@@ -54,7 +52,7 @@ Requests in top-level queue : 0
54
52
 
55
53
  /home/application_3/Site#default:
56
54
  App root: /home/application_3/Site
57
- Requests in queue: 0
55
+ Requests in queue: 3
58
56
  * PID: 17507 Sessions: 0 Processed: 2141 Uptime: 21h 43m 33s
59
57
  CPU: 0% Memory : 242M Last used: 5h 51m
60
58
  * PID: 17514 Sessions: 0 Processed: 5967 Uptime: 21h 43m 33s
@@ -70,7 +68,7 @@ Requests in top-level queue : 0
70
68
 
71
69
  /home/application_4/Site#default:
72
70
  App root: /home/application_4/Site
73
- Requests in queue: 0
71
+ Requests in queue: 4
74
72
  * PID: 32383 Sessions: 0 Processed: 2182 Uptime: 2h 7m 9s
75
73
  CPU: 0% Memory : 76M Last used: 2s ago
76
74
  * PID: 23605 Sessions: 0 Processed: 609 Uptime: 1h 7m 25s
@@ -80,3 +78,4 @@ Requests in top-level queue : 0
80
78
  * PID: 24379 Sessions: 0 Processed: 275 Uptime: 32m 7s
81
79
  CPU: 0% Memory : 59M Last used: 0s ago
82
80
 
81
+ HEREDOC
@@ -4,12 +4,12 @@ Instance: 32028
4
4
  ----------- General information -----------
5
5
  Max pool size : 40
6
6
  Processes : 26
7
- Requests in top-level queue : 0
7
+ Requests in top-level queue : 10
8
8
 
9
9
  ----------- Application groups -----------
10
10
  /home/application_1/Site#default:
11
11
  App root: /home/application_1/Site
12
- Requests in queue: 0
12
+ Requests in queue: 11
13
13
  * PID: 12396 Sessions: 0 Processed: 13322 Uptime: 19h 12m 52s
14
14
  CPU: 0% Memory : 153M Last used: 51m 29s
15
15
  * PID: 12404 Sessions: 0 Processed: 11694 Uptime: 19h 12m 52s
@@ -37,7 +37,7 @@ Requests in top-level queue : 0
37
37
 
38
38
  /home/application_2/Site#default:
39
39
  App root: /home/application_2/Site
40
- Requests in queue: 0
40
+ Requests in queue: 12
41
41
  * PID: 26712 Sessions: 0 Processed: 184 Uptime: 21h 36m 36s
42
42
  CPU: 0% Memory : 26M Last used: 1m 11s
43
43
  * PID: 26721 Sessions: 0 Processed: 0 Uptime: 21h 36m 35s
@@ -49,7 +49,7 @@ Requests in top-level queue : 0
49
49
 
50
50
  /home/application_3/Site#default:
51
51
  App root: /home/application_3/Site
52
- Requests in queue: 0
52
+ Requests in queue: 13
53
53
  * PID: 17507 Sessions: 0 Processed: 2141 Uptime: 21h 43m 33s
54
54
  CPU: 0% Memory : 242M Last used: 5h 51m
55
55
  * PID: 17514 Sessions: 0 Processed: 5967 Uptime: 21h 43m 33s
@@ -65,7 +65,7 @@ Requests in top-level queue : 0
65
65
 
66
66
  /home/application_4/Site#default:
67
67
  App root: /home/application_4/Site
68
- Requests in queue: 0
68
+ Requests in queue: 14
69
69
  * PID: 32383 Sessions: 0 Processed: 2182 Uptime: 2h 7m 9s
70
70
  CPU: 0% Memory : 76M Last used: 2s ago
71
71
  * PID: 23605 Sessions: 0 Processed: 609 Uptime: 1h 7m 25s
@@ -4,12 +4,12 @@ Instance: 28669
4
4
  ----------- General information -----------
5
5
  Max pool size : 40
6
6
  Processes : 22
7
- Requests in top-level queue : 0
7
+ Requests in top-level queue : 12
8
8
 
9
9
  ----------- Application groups -----------
10
10
  /home/application_1/Site#default:
11
11
  App root: /home/application_1/Site
12
- Requests in queue: 0
12
+ Requests in queue: 21
13
13
  * PID: 10966 Sessions: 0 Processed: 10840 Uptime: 15h 39m 16s
14
14
  CPU: 1% Memory : 170M Last used: 17s ago
15
15
  * PID: 10974 Sessions: 0 Processed: 0 Uptime: 15h 39m 16s
@@ -37,7 +37,7 @@ Requests in top-level queue : 0
37
37
 
38
38
  /home/application_2/Site#default:
39
39
  App root: /home/application_2/Site
40
- Requests in queue: 0
40
+ Requests in queue: 22
41
41
  * PID: 1679 Sessions: 0 Processed: 1273 Uptime: 3d 17h 40m 10s
42
42
  CPU: 0% Memory : 45M Last used: 6m 4
43
43
  * PID: 1686 Sessions: 0 Processed: 0 Uptime: 3d 17h 40m 10s
@@ -49,7 +49,7 @@ Requests in top-level queue : 0
49
49
 
50
50
  /home/application_3/Site#default:
51
51
  App root: /home/application_3/Site
52
- Requests in queue: 0
52
+ Requests in queue: 23
53
53
  * PID: 8170 Sessions: 0 Processed: 13179 Uptime: 1d 12h 8m 46s
54
54
  CPU: 1% Memory : 612M Last used: 0s ag
55
55
  * PID: 8180 Sessions: 0 Processed: 20043 Uptime: 1d 12h 8m 45s
@@ -4,24 +4,24 @@ Instance: 1965
4
4
  ----------- General information -----------
5
5
  Max pool size : 50
6
6
  Processes : 6
7
- Requests in top-level queue : 0
7
+ Requests in top-level queue : 13
8
8
 
9
9
  ----------- Application groups -----------
10
10
  /home/application_1/Site#default:
11
11
  App root: /home/application_1/Site
12
- Requests in queue: 0
12
+ Requests in queue: 1
13
13
  * PID: 14518 Sessions: 0 Processed: 11723 Uptime: 20h 8m 7s
14
14
  CPU: 0% Memory : 144M Last used: 1m 33s ag
15
15
 
16
16
  /home/application_2/Site#default:
17
17
  App root: /home/application_2/Site
18
- Requests in queue: 0
18
+ Requests in queue: 32
19
19
  * PID: 14134 Sessions: 0 Processed: 2313 Uptime: 20h 8m 10s
20
20
  CPU: 0% Memory : 63M Last used: 6h 22m 4
21
21
 
22
22
  /home/application_3/Site#default:
23
23
  App root: /home/application_3/Site
24
- Requests in queue: 0
24
+ Requests in queue: 33
25
25
  * PID: 21058 Sessions: 0 Processed: 725 Uptime: 2d 22h 35m 38s
26
26
  CPU: 0% Memory : 30M Last used: 5m 4
27
27
  * PID: 21071 Sessions: 0 Processed: 0 Uptime: 2d 22h 35m 38s
@@ -5,7 +5,7 @@ describe CheckPassenger::Check do
5
5
  it 'returns a PassengerStatus class' do
6
6
  assert_equal 'CheckPassenger::PassengerStatus', CheckPassenger::Check.send(:passenger_status).name
7
7
  assert_equal 'CheckPassenger::PassengerStatus',
8
- CheckPassenger::Check.send(:passenger_status, File.dirname(__FILE__)).name
8
+ CheckPassenger::Check.send(:passenger_status, File.dirname(__FILE__)).name
9
9
  end
10
10
  end
11
11
 
@@ -14,9 +14,9 @@ describe CheckPassenger::Check do
14
14
 
15
15
  output_data.each do |datum|
16
16
  assert_kind_of Hash, datum
17
- assert datum.has_key?(:text)
18
- assert datum.has_key?(:counter)
19
- assert datum.has_key?(:value)
17
+ assert datum.key?(:text)
18
+ assert datum.key?(:counter)
19
+ assert datum.key?(:value)
20
20
  end
21
21
  end
22
22
 
@@ -29,7 +29,7 @@ describe CheckPassenger::Check do
29
29
 
30
30
  describe '#process_count' do
31
31
  it 'reports global process count' do
32
- options = { parsed_data: @parsed_data }
32
+ options = {parsed_data: @parsed_data}
33
33
  output_status, output_data = CheckPassenger::Check.process_count(options)
34
34
 
35
35
  assert_equal :ok, output_status
@@ -40,7 +40,7 @@ describe CheckPassenger::Check do
40
40
  end
41
41
 
42
42
  it 'reports global memory' do
43
- options = { parsed_data: @parsed_data }
43
+ options = {parsed_data: @parsed_data}
44
44
  output_status, output_data = CheckPassenger::Check.memory(options)
45
45
 
46
46
  assert :ok, output_status
@@ -51,7 +51,7 @@ describe CheckPassenger::Check do
51
51
  end
52
52
 
53
53
  it 'reports data for all applications' do
54
- options = { parsed_data: @parsed_data, include_all: true }
54
+ options = {parsed_data: @parsed_data, include_all: true}
55
55
  [:process_count, :memory, :live_process_count].each do |counter|
56
56
  output_status, output_data = CheckPassenger::Check.send(counter, options)
57
57
 
@@ -63,7 +63,7 @@ describe CheckPassenger::Check do
63
63
  end
64
64
 
65
65
  it 'reports global live process count' do
66
- options = { parsed_data: @parsed_data }
66
+ options = {parsed_data: @parsed_data}
67
67
  output_status, output_data = CheckPassenger::Check.live_process_count(options)
68
68
 
69
69
  assert :ok, output_status
@@ -73,8 +73,30 @@ describe CheckPassenger::Check do
73
73
  assert_equal 9, output_data.first[:value]
74
74
  end
75
75
 
76
+ it 'reports global request queue' do
77
+ options = {parsed_data: @parsed_data}
78
+ output_status, output_data = CheckPassenger::Check.request_count(options)
79
+
80
+ assert :ok, output_status
81
+ output_data_structure_test(output_data)
82
+
83
+ assert_equal 'request_count', output_data.first[:counter]
84
+ assert_equal 60, output_data.first[:value]
85
+ end
86
+
87
+ it 'reports top-level queue size' do
88
+ options = {parsed_data: @parsed_data}
89
+ output_status, output_data = CheckPassenger::Check.top_level_request_count(options)
90
+
91
+ assert :ok, output_status
92
+ output_data_structure_test(output_data)
93
+
94
+ assert_equal 'top_level_request_count', output_data.first[:counter]
95
+ assert_equal 10, output_data.first[:value]
96
+ end
97
+
76
98
  it 'reports application process count' do
77
- options = { parsed_data: @parsed_data, app_name: 'application_1' }
99
+ options = {parsed_data: @parsed_data, app_name: 'application_1'}
78
100
  output_status, output_data = CheckPassenger::Check.process_count(options)
79
101
 
80
102
  assert_equal :ok, output_status
@@ -85,7 +107,7 @@ describe CheckPassenger::Check do
85
107
  end
86
108
 
87
109
  it 'reports application memory' do
88
- options = { parsed_data: @parsed_data, app_name: 'application_2' }
110
+ options = {parsed_data: @parsed_data, app_name: 'application_2'}
89
111
  output_status, output_data = CheckPassenger::Check.memory(options)
90
112
 
91
113
  assert_equal :ok, output_status
@@ -96,7 +118,7 @@ describe CheckPassenger::Check do
96
118
  end
97
119
 
98
120
  it 'reports application live process count' do
99
- options = { parsed_data: @parsed_data, app_name: 'application_3' }
121
+ options = {parsed_data: @parsed_data, app_name: 'application_3'}
100
122
  output_status, output_data = CheckPassenger::Check.live_process_count(options)
101
123
 
102
124
  assert_equal :ok, output_status
@@ -106,15 +128,26 @@ describe CheckPassenger::Check do
106
128
  assert_equal 1, output_data.first[:value]
107
129
  end
108
130
 
131
+ it 'reports application request queue count' do
132
+ options = {parsed_data: @parsed_data, app_name: 'application_4'}
133
+ output_status, output_data = CheckPassenger::Check.request_count(options)
134
+
135
+ assert_equal :ok, output_status
136
+ output_data_structure_test(output_data)
137
+
138
+ assert_equal 'request_count', output_data.first[:counter]
139
+ assert_equal 14, output_data.first[:value]
140
+ end
141
+
109
142
  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)
143
+ options = {parsed_data: @parsed_data, app_name: 'application_4', warn: '150', crit: '300'}
144
+ output_status, _output_data = CheckPassenger::Check.memory(options)
112
145
  assert_equal :warn, output_status
113
146
  end
114
147
 
115
148
  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)
149
+ options = {parsed_data: @parsed_data, app_name: 'application_4', warn: '75', crit: '150'}
150
+ output_status, _output_data = CheckPassenger::Check.memory(options)
118
151
  assert_equal :crit, output_status
119
152
  end
120
153
  end
@@ -128,33 +161,43 @@ describe CheckPassenger::Check do
128
161
  end
129
162
 
130
163
  it 'correctly uses singular/plural when reporting counts' do
131
- options = { parsed_data: @parsed_data }
132
- output_status, output_data = CheckPassenger::Check.process_count(options)
164
+ options = {parsed_data: @parsed_data}
165
+ _output_status, output_data = CheckPassenger::Check.process_count(options)
133
166
  assert output_data.first[:text] =~ /\b6 processes\b/, output_data.first[:text]
134
- output_status, output_data = CheckPassenger::Check.live_process_count(options)
167
+ _output_status, output_data = CheckPassenger::Check.live_process_count(options)
135
168
  assert output_data.first[:text] =~ /\b1 live process\b/, output_data.first[:text]
169
+ _output_status, output_data = CheckPassenger::Check.request_count(options)
170
+ assert output_data.first[:text] =~ /\b79 requests\b/, output_data.first[:text]
171
+ _output_status, output_data = CheckPassenger::Check.top_level_request_count(options)
172
+ assert output_data.first[:text] =~ /\b13 top-level requests\b/, output_data.first[:text]
136
173
 
137
- options = { parsed_data: @parsed_data, app_name: 'application_1' }
138
- output_status, output_data = CheckPassenger::Check.process_count(options)
174
+ options = {parsed_data: @parsed_data, app_name: 'application_1'}
175
+ _output_status, output_data = CheckPassenger::Check.process_count(options)
139
176
  assert output_data.first[:text] =~ /\b1 process\b/, output_data.first[:text]
140
- output_status, output_data = CheckPassenger::Check.live_process_count(options)
177
+ _output_status, output_data = CheckPassenger::Check.live_process_count(options)
141
178
  assert output_data.first[:text] =~ /\b1 live process\b/, output_data.first[:text]
179
+ _output_status, output_data = CheckPassenger::Check.request_count(options)
180
+ assert output_data.first[:text] =~ /\b1 request\b/, output_data.first[:text]
142
181
 
143
- options = { parsed_data: @parsed_data, app_name: 'application_2' }
144
- output_status, output_data = CheckPassenger::Check.process_count(options)
182
+ options = {parsed_data: @parsed_data, app_name: 'application_2'}
183
+ _output_status, output_data = CheckPassenger::Check.process_count(options)
145
184
  assert output_data.first[:text] =~ /\b1 process\b/, output_data.first[:text]
146
- output_status, output_data = CheckPassenger::Check.live_process_count(options)
185
+ _output_status, output_data = CheckPassenger::Check.live_process_count(options)
147
186
  assert output_data.first[:text] =~ /\b0 live processes\b/, output_data.first[:text]
187
+ _output_status, output_data = CheckPassenger::Check.request_count(options)
188
+ assert output_data.first[:text] =~ /\b32 requests\b/, output_data.first[:text]
148
189
 
149
- options = { parsed_data: @parsed_data, app_name: 'application_3' }
150
- output_status, output_data = CheckPassenger::Check.process_count(options)
190
+ options = {parsed_data: @parsed_data, app_name: 'application_3'}
191
+ _output_status, output_data = CheckPassenger::Check.process_count(options)
151
192
  assert output_data.first[:text] =~ /\b4 processes\b/, output_data.first[:text]
152
- output_status, output_data = CheckPassenger::Check.live_process_count(options)
193
+ _output_status, output_data = CheckPassenger::Check.live_process_count(options)
153
194
  assert output_data.first[:text] =~ /\b0 live processes\b/, output_data.first[:text]
195
+ _output_status, output_data = CheckPassenger::Check.request_count(options)
196
+ assert output_data.first[:text] =~ /\b33 requests\b/, output_data.first[:text]
154
197
  end
155
198
 
156
199
  it 'raises an alert if the application is not running' do
157
- options = { parsed_data: @parsed_data, app_name: 'application_4' }
200
+ options = {parsed_data: @parsed_data, app_name: 'application_4'}
158
201
  output_status, output_data = CheckPassenger::Check.process_count(options)
159
202
  assert_equal :crit, output_status, output_data.inspect
160
203
  end