bin/metrics-sqs.rb in sensu-plugins-aws-8.3.1 vs bin/metrics-sqs.rb in sensu-plugins-aws-9.0.0
- old
+ new
@@ -10,29 +10,32 @@
#
# PLATFORMS:
# Linux
#
# DEPENDENCIES:
-# gem: aws-sdk-v1
+# gem: aws-sdk
# gem: sensu-plugin
#
# USAGE:
-# metrics-sqs -q my_queue -a key -k secret
-# metrics-sqs -p queue_prefix_ -a key -k secret
+# metrics-sqs -q my_queue
+# metrics-sqs -p queue_prefix_
#
# NOTES:
#
# LICENSE:
# Copyright 2015 Eric Heydrick <eheydrick@gmail.com>
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.
#
require 'sensu-plugin/metric/cli'
-require 'aws-sdk-v1'
+require 'sensu-plugins-aws'
+require 'aws-sdk'
class SQSMetrics < Sensu::Plugin::Metric::CLI::Graphite
+ include Common
+
option :queue,
description: 'Name of the queue',
short: '-q QUEUE',
long: '--queue QUEUE',
default: ''
@@ -47,22 +50,10 @@
description: 'Metric naming scheme, text to prepend to metric',
short: '-s SCHEME',
long: '--scheme SCHEME',
default: ''
- option :aws_access_key,
- description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option",
- short: '-a AWS_ACCESS_KEY',
- long: '--aws-access-key AWS_ACCESS_KEY',
- default: ENV['AWS_ACCESS_KEY']
-
- option :aws_secret_access_key,
- description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_ACCESS_KEY'] or provide it as an option",
- short: '-k AWS_SECRET_KEY',
- long: '--aws-secret-access-key AWS_SECRET_KEY',
- default: ENV['AWS_SECRET_KEY']
-
option :aws_region,
description: 'AWS Region (defaults to us-east-1).',
short: '-r AWS_REGION',
long: '--aws-region AWS_REGION',
default: 'us-east-1'
@@ -77,27 +68,27 @@
scheme = config[:scheme].empty? ? 'aws.sqs.queue' : config[:scheme]
"#{scheme}.#{queue_name.tr('-', '_')}.message_count"
end
def record_queue_metrics(q_name, q)
- output scheme(q_name), q.approximate_number_of_messages
- output "#{scheme(q_name)}.delayed", q.approximate_number_of_messages_delayed
- output "#{scheme(q_name)}.not_visible", q.approximate_number_of_messages_not_visible
+ output scheme(q_name), q.attributes['ApproximateNumberOfMessages'].to_i
+ output "#{scheme(q_name)}.delayed", q.attributes['ApproximateNumberOfMessagesDelayed'].to_i
+ output "#{scheme(q_name)}.not_visible", q.attributes['ApproximateNumberOfMessagesNotVisible'].to_i
end
def run
begin
- sqs = AWS::SQS.new aws_config
+ sqs = Aws::SQS::Resource.new(aws_config)
if config[:prefix] == ''
if config[:queue] == ''
critical 'Error, either QUEUE or PREFIX must be specified'
end
- record_queue_metrics(config[:queue], sqs.queues.named(config[:queue]))
+ record_queue_metrics(config[:queue], sqs.get_queue_by_name(queue_name: config[:queue]))
else
- sqs.queues.with_prefix(config[:prefix]).each do |q|
- record_queue_metrics(q.arn.split(':').last, q)
+ sqs.queues(queue_name_prefix: config[:prefix]).each do |q|
+ record_queue_metrics(q.attributes['QueueArn'].split(':').last, q)
end
end
rescue => e
critical "Error fetching SQS queue metrics: #{e.message}"
end