sensu-plugins-rabbitmq-temp 1.4.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.
@@ -0,0 +1,138 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ #
4
+ # RabbitMQ Queue Drain Time
5
+ # ===
6
+ #
7
+ # DESCRIPTION:
8
+ # This plugin checks the time it will take for each queue on the RabbitMQ
9
+ # server to drain based on the current message egress rate. For example
10
+ # if a queue has 1,000 messages in it, but egresses only 1 message a sec
11
+ # the alert would fire as this is greater than the default critical level of 360s
12
+ #
13
+ # The plugin is based on the RabbitMQ Queue Metrics plugin
14
+ #
15
+ # PLATFORMS:
16
+ # Linux, BSD, Solaris
17
+ #
18
+ # DEPENDENCIES:
19
+ # RabbitMQ rabbitmq_management plugin
20
+ # gem: sensu-plugin
21
+ # gem: carrot-top
22
+ #
23
+ # LICENSE:
24
+ # Copyright 2015 Tim Smith <tim@cozy.co> and Cozy Services Ltd.
25
+ #
26
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
27
+ # for details.
28
+
29
+ require 'sensu-plugin/check/cli'
30
+ require 'socket'
31
+ require 'carrot-top'
32
+
33
+ # main plugin class
34
+ class CheckRabbitMQQueueDrainTime < Sensu::Plugin::Check::CLI
35
+ option :host,
36
+ description: 'RabbitMQ management API host',
37
+ long: '--host HOST',
38
+ default: 'localhost'
39
+
40
+ option :port,
41
+ description: 'RabbitMQ management API port',
42
+ long: '--port PORT',
43
+ proc: proc(&:to_i),
44
+ default: 15_672
45
+
46
+ option :vhost,
47
+ description: 'Regular expression for filtering the RabbitMQ vhost',
48
+ short: '-v',
49
+ long: '--vhost VHOST'
50
+
51
+ option :user,
52
+ description: 'RabbitMQ management API user',
53
+ long: '--user USER',
54
+ default: 'guest'
55
+
56
+ option :password,
57
+ description: 'RabbitMQ management API password',
58
+ long: '--password PASSWORD',
59
+ default: 'guest'
60
+
61
+ option :filter,
62
+ description: 'Regular expression for filtering queues',
63
+ long: '--filter REGEX'
64
+
65
+ option :ssl,
66
+ description: 'Enable SSL for connection to the API',
67
+ long: '--ssl',
68
+ boolean: true,
69
+ default: false
70
+
71
+ option :warn,
72
+ short: '-w PROCESS_TIME_SECS',
73
+ long: '--warning PROCESS_TIME_SECS',
74
+ description: 'WARNING that messages will process at current rate',
75
+ default: 180
76
+
77
+ option :critical,
78
+ short: '-c PROCESS_TIME_SECS',
79
+ long: '--critical PROCESS_TIME_SECS',
80
+ description: 'CRITICAL time that messages will process at current rate',
81
+ default: 360
82
+
83
+ def acquire_rabbitmq_queues
84
+ begin
85
+ rabbitmq_info = CarrotTop.new(
86
+ host: config[:host],
87
+ port: config[:port],
88
+ user: config[:user],
89
+ password: config[:password],
90
+ ssl: config[:ssl]
91
+ )
92
+ rescue
93
+ warning 'could not get rabbitmq queue info'
94
+ end
95
+
96
+ queues = rabbitmq_info.queues.select { |q| q['name'].match(Regexp.new(config[:filter])) }
97
+
98
+ if config[:vhost]
99
+ return queues.select { |x| x['vhost'].match(config[:vhost]) }
100
+ end
101
+
102
+ queues
103
+ end
104
+
105
+ def run
106
+ warn_queues = {}
107
+ crit_queues = {}
108
+
109
+ acquire_rabbitmq_queues.each do |queue|
110
+ # we don't care about empty queues and they'll have an infinite drain time so skip them
111
+ next if queue['messages'] == 0 || queue['messages'].nil?
112
+
113
+ # handle rate of zero which is an infinite time until empty
114
+ if queue['backing_queue_status']['avg_egress_rate'].to_f == 0
115
+ crit_queues[queue['name']] = 'Infinite (drain rate = 0)'
116
+ next
117
+ end
118
+
119
+ secs_till_empty = queue['messages'] / queue['backing_queue_status']['avg_egress_rate']
120
+
121
+ # place warn / crit counts into hashes to be parsed for the alert message
122
+ if secs_till_empty > config[:critical].to_i
123
+ crit_queues[queue['name']] = secs_till_empty
124
+ elsif secs_till_empty > config[:warn].to_i
125
+ warn_queues[queue['name']] = secs_till_empty
126
+ end
127
+ end
128
+
129
+ # decide if we need to alert and build the message
130
+ if !crit_queues.empty?
131
+ critical "Drain time: #{crit_queues.map { |q, c| "#{q} #{c} sec" }.join(', ')}"
132
+ elsif !warn_queues.empty?
133
+ warning "Drain time: #{warn_queues.map { |q, c| "#{q} #{c} sec" }.join(', ')}"
134
+ else
135
+ ok "All (#{acquire_rabbitmq_queues.count}) queues will be drained in under #{config[:warn].to_i} seconds"
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ #
4
+ # Check RabbitMQ Queue Messages
5
+ # ===
6
+ #
7
+ # DESCRIPTION:
8
+ # This plugin checks the number of messages queued on the RabbitMQ server in a specific queues
9
+ #
10
+ # PLATFORMS:
11
+ # Linux, BSD, Solaris
12
+ #
13
+ # DEPENDENCIES:
14
+ # RabbitMQ rabbitmq_management plugin
15
+ # gem: sensu-plugin
16
+ # gem: carrot-top
17
+ #
18
+ # LICENSE:
19
+ # Copyright 2012 Evan Hazlett <ejhazlett@gmail.com>
20
+ #
21
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
22
+ # for details.
23
+
24
+ require 'sensu-plugin/check/cli'
25
+ require 'socket'
26
+ require 'carrot-top'
27
+
28
+ # main plugin class
29
+ class CheckRabbitMQMessages < Sensu::Plugin::Check::CLI
30
+ option :host,
31
+ description: 'RabbitMQ management API host',
32
+ long: '--host HOST',
33
+ default: 'localhost'
34
+
35
+ option :port,
36
+ description: 'RabbitMQ management API port',
37
+ long: '--port PORT',
38
+ proc: proc(&:to_i),
39
+ default: 15_672
40
+
41
+ option :vhost,
42
+ description: 'RabbitMQ vhost',
43
+ short: '-v',
44
+ long: '--vhost VHOST',
45
+ default: ''
46
+
47
+ option :ssl,
48
+ description: 'Enable SSL for connection to the API',
49
+ long: '--ssl',
50
+ boolean: true,
51
+ default: false
52
+
53
+ option :user,
54
+ description: 'RabbitMQ management API user',
55
+ long: '--user USER',
56
+ default: 'guest'
57
+
58
+ option :password,
59
+ description: 'RabbitMQ management API password',
60
+ long: '--password PASSWORD',
61
+ default: 'guest'
62
+
63
+ option :queue,
64
+ description: 'RabbitMQ queue to monitor',
65
+ long: '--queue queue_names',
66
+ required: true,
67
+ proc: proc { |a| a.split(',') }
68
+
69
+ option :warn,
70
+ short: '-w NUM_MESSAGES',
71
+ long: '--warn NUM_MESSAGES',
72
+ description: 'WARNING message count threshold',
73
+ default: 250
74
+
75
+ option :critical,
76
+ short: '-c NUM_MESSAGES',
77
+ long: '--critical NUM_MESSAGES',
78
+ description: 'CRITICAL message count threshold',
79
+ default: 500
80
+
81
+ option :ignore,
82
+ description: 'Ignore non-existent queues',
83
+ long: '--ignore',
84
+ boolean: true,
85
+ default: false
86
+
87
+ def acquire_rabbitmq_info
88
+ begin
89
+ rabbitmq_info = CarrotTop.new(
90
+ host: config[:host],
91
+ port: config[:port],
92
+ user: config[:user],
93
+ password: config[:password],
94
+ ssl: config[:ssl]
95
+ )
96
+ rescue
97
+ warning 'could not get rabbitmq info'
98
+ end
99
+ rabbitmq_info
100
+ end
101
+
102
+ def run
103
+ @crit = []
104
+ @warn = []
105
+ rabbitmq = acquire_rabbitmq_info
106
+ queues = rabbitmq.method_missing('/queues/' + config[:vhost])
107
+ config[:queue].each do |q|
108
+ unless queues.map { |hash| hash['name'] }.include? q
109
+ unless config[:ignore]
110
+ @warn << "Queue #{q} not available"
111
+ end
112
+ next
113
+ end
114
+ queues.each do |queue|
115
+ next unless queue['name'] == q
116
+ total = queue['messages']
117
+ total = 0 if total.nil?
118
+ message total.to_s
119
+ @crit << "#{q}:#{total}" if total > config[:critical].to_i
120
+ @warn << "#{q}:#{total}" if total > config[:warn].to_i
121
+ end
122
+ end
123
+ if @crit.empty? && @warn.empty?
124
+ ok
125
+ elsif !@crit.empty?
126
+ critical "critical: #{@crit} warning: #{@warn}"
127
+ elsif !@warn.empty?
128
+ warning "critical: #{@crit} warning: #{@warn}"
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ #
4
+ # RabbitMQ check alive plugin
5
+ # ===
6
+ #
7
+ # DESCRIPTION:
8
+ # This plugin checks if RabbitMQ server is alive and responding to STOMP
9
+ # requests.
10
+ #
11
+ # Based on rabbitmq-amqp-alive by Milos Gajdos
12
+ #
13
+ # PLATFORMS:
14
+ # Linux, BSD, Solaris
15
+ #
16
+ # DEPENDENCIES:
17
+ # RabbitMQ rabbitmq_management plugin
18
+ # gem: sensu-plugin
19
+ # gem: stomp
20
+ #
21
+ # LICENSE:
22
+ # Copyright 2014 Adam Ashley
23
+ #
24
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
25
+ # for details.
26
+
27
+ require 'sensu-plugin/check/cli'
28
+ require 'stomp'
29
+
30
+ # main plugin class
31
+ class CheckRabbitStomp < Sensu::Plugin::Check::CLI
32
+ option :host,
33
+ description: 'RabbitMQ host',
34
+ short: '-w',
35
+ long: '--host HOST',
36
+ default: 'localhost'
37
+
38
+ option :username,
39
+ description: 'RabbitMQ username',
40
+ short: '-u',
41
+ long: '--username USERNAME',
42
+ default: 'guest'
43
+
44
+ option :password,
45
+ description: 'RabbitMQ password',
46
+ short: '-p',
47
+ long: '--password PASSWORD',
48
+ default: 'guest'
49
+
50
+ option :port,
51
+ description: 'RabbitMQ STOMP port',
52
+ short: '-P',
53
+ long: '--port PORT',
54
+ default: '61613'
55
+
56
+ option :ssl,
57
+ description: 'Enable SSL for connection to RabbitMQ',
58
+ long: '--ssl',
59
+ boolean: true,
60
+ default: false
61
+
62
+ option :queue,
63
+ description: 'Queue to post a message to and receive from',
64
+ short: '-q',
65
+ long: '--queue QUEUE',
66
+ default: 'aliveness-test'
67
+
68
+ def run
69
+ res = vhost_alive?
70
+
71
+ if res['status'] == 'ok'
72
+ ok res['message']
73
+ elsif res['status'] == 'critical'
74
+ critical res['message']
75
+ else
76
+ unknown res['message']
77
+ end
78
+ end
79
+
80
+ def vhost_alive?
81
+ hash = {
82
+ hosts: [
83
+ {
84
+ login: config[:username],
85
+ passcode: config[:password],
86
+ host: config[:host],
87
+ port: config[:port],
88
+ ssl: config[:ssl]
89
+ }
90
+ ],
91
+ reliable: false, # disable failover
92
+ connect_timeout: 10
93
+ }
94
+
95
+ begin
96
+ conn = Stomp::Client.new(hash)
97
+ conn.publish("/queue/#{config[:queue]}", 'STOMP Alive Test')
98
+ conn.subscribe("/queue/#{config[:queue]}") do |_msg|
99
+ end
100
+ { 'status' => 'ok', 'message' => 'RabbitMQ server is alive' }
101
+ rescue Errno::ECONNREFUSED
102
+ { 'status' => 'critical', 'message' => 'TCP connection refused' }
103
+ rescue Stomp::Error::BrokerException => e
104
+ { 'status' => 'critical', 'message' => "Error from broker. Check auth details? #{e.message}" }
105
+ rescue => e
106
+ { 'status' => 'unknown', 'message' => "#{e.class}: #{e.message}" }
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,142 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ #
4
+ # RabbitMQ Overview Metrics
5
+ # ===
6
+ #
7
+ # DESCRIPTION:
8
+ # RabbitMQ 'overview' stats are similar to what is shown on the main page
9
+ # of the rabbitmq_management web UI. Example:
10
+ #
11
+ # $ rabbitmq-queue-metrics.rb
12
+ # host.rabbitmq.queue_totals.messages.count 0 1344186404
13
+ # host.rabbitmq.queue_totals.messages.rate 0.0 1344186404
14
+ # host.rabbitmq.queue_totals.messages_unacknowledged.count 0 1344186404
15
+ # host.rabbitmq.queue_totals.messages_unacknowledged.rate 0.0 1344186404
16
+ # host.rabbitmq.queue_totals.messages_ready.count 0 1344186404
17
+ # host.rabbitmq.queue_totals.messages_ready.rate 0.0 1344186404
18
+ # host.rabbitmq.message_stats.publish.count 4605755 1344186404
19
+ # host.rabbitmq.message_stats.publish.rate 17.4130186829638 1344186404
20
+ # host.rabbitmq.message_stats.deliver_no_ack.count 6661111 1344186404
21
+ # host.rabbitmq.message_stats.deliver_no_ack.rate 24.6867565643405 1344186404
22
+ # host.rabbitmq.message_stats.deliver_get.count 6661111 1344186404
23
+ # host.rabbitmq.message_stats.deliver_get.rate 24.6867565643405 1344186404#
24
+ #
25
+ # PLATFORMS:
26
+ # Linux, BSD, Solaris
27
+ #
28
+ # DEPENDENCIES:
29
+ # RabbitMQ rabbitmq_management plugin
30
+ # gem: sensu-plugin
31
+ # gem: carrot-top
32
+ #
33
+ # LICENSE:
34
+ # Copyright 2012 Joe Miller - https://github.com/joemiller
35
+ #
36
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
37
+ # for details.
38
+
39
+ require 'sensu-plugin/metric/cli'
40
+ require 'socket'
41
+ require 'carrot-top'
42
+
43
+ # main plugin class
44
+ class RabbitMQMetrics < Sensu::Plugin::Metric::CLI::Graphite
45
+ option :host,
46
+ description: 'RabbitMQ management API host',
47
+ long: '--host HOST',
48
+ default: 'localhost'
49
+
50
+ option :port,
51
+ description: 'RabbitMQ management API port',
52
+ long: '--port PORT',
53
+ proc: proc(&:to_i),
54
+ default: 15_672
55
+
56
+ option :user,
57
+ description: 'RabbitMQ management API user',
58
+ long: '--user USER',
59
+ default: 'guest'
60
+
61
+ option :password,
62
+ description: 'RabbitMQ management API password',
63
+ long: '--password PASSWORD',
64
+ default: 'guest'
65
+
66
+ option :scheme,
67
+ description: 'Metric naming scheme, text to prepend to $queue_name.$metric',
68
+ long: '--scheme SCHEME',
69
+ default: "#{Socket.gethostname}.rabbitmq"
70
+
71
+ option :ssl,
72
+ description: 'Enable SSL for connection to the API',
73
+ long: '--ssl',
74
+ boolean: true,
75
+ default: false
76
+
77
+ def acquire_rabbitmq_info
78
+ begin
79
+ rabbitmq_info = CarrotTop.new(
80
+ host: config[:host],
81
+ port: config[:port],
82
+ user: config[:user],
83
+ password: config[:password],
84
+ ssl: config[:ssl]
85
+ )
86
+ rescue
87
+ warning 'could not get rabbitmq info'
88
+ end
89
+ rabbitmq_info
90
+ end
91
+
92
+ def run #rubocop:disable all
93
+ timestamp = Time.now.to_i
94
+
95
+ rabbitmq = acquire_rabbitmq_info
96
+ overview = rabbitmq.overview
97
+
98
+ # overview['queue_totals']['messages']
99
+ if overview.key?('queue_totals') && !overview['queue_totals'].empty?
100
+ output "#{config[:scheme]}.queue_totals.messages.count", overview['queue_totals']['messages'], timestamp
101
+ output "#{config[:scheme]}.queue_totals.messages.rate", overview['queue_totals']['messages_details']['rate'], timestamp
102
+
103
+ # overview['queue_totals']['messages_unacknowledged']
104
+ output "#{config[:scheme]}.queue_totals.messages_unacknowledged.count", overview['queue_totals']['messages_unacknowledged'], timestamp
105
+ output "#{config[:scheme]}.queue_totals.messages_unacknowledged.rate", overview['queue_totals']['messages_unacknowledged_details']['rate'], timestamp
106
+
107
+ # overview['queue_totals']['messages_ready']
108
+ output "#{config[:scheme]}.queue_totals.messages_ready.count", overview['queue_totals']['messages_ready'], timestamp
109
+ output "#{config[:scheme]}.queue_totals.messages_ready.rate", overview['queue_totals']['messages_ready_details']['rate'], timestamp
110
+ end
111
+
112
+ if overview.key?('message_stats') && !overview['message_stats'].empty?
113
+ # overview['message_stats']['publish']
114
+ if overview['message_stats'].include?('publish')
115
+ output "#{config[:scheme]}.message_stats.publish.count", overview['message_stats']['publish'], timestamp
116
+ end
117
+ if overview['message_stats'].include?('publish_details') &&
118
+ overview['message_stats']['publish_details'].include?('rate')
119
+ output "#{config[:scheme]}.message_stats.publish.rate", overview['message_stats']['publish_details']['rate'], timestamp
120
+ end
121
+
122
+ # overview['message_stats']['deliver_no_ack']
123
+ if overview['message_stats'].include?('deliver_no_ack')
124
+ output "#{config[:scheme]}.message_stats.deliver_no_ack.count", overview['message_stats']['deliver_no_ack'], timestamp
125
+ end
126
+ if overview['message_stats'].include?('deliver_no_ack_details') &&
127
+ overview['message_stats']['deliver_no_ack_details'].include?('rate')
128
+ output "#{config[:scheme]}.message_stats.deliver_no_ack.rate", overview['message_stats']['deliver_no_ack_details']['rate'], timestamp
129
+ end
130
+
131
+ # overview['message_stats']['deliver_get']
132
+ if overview['message_stats'].include?('deliver_get')
133
+ output "#{config[:scheme]}.message_stats.deliver_get.count", overview['message_stats']['deliver_get'], timestamp
134
+ end
135
+ if overview['message_stats'].include?('deliver_get_details') &&
136
+ overview['message_stats']['deliver_get_details'].include?('rate')
137
+ output "#{config[:scheme]}.message_stats.deliver_get.rate", overview['message_stats']['deliver_get_details']['rate'], timestamp
138
+ end
139
+ end
140
+ ok
141
+ end
142
+ end