bin/metrics-sqs.rb in sensu-plugins-aws-3.1.0 vs bin/metrics-sqs.rb in sensu-plugins-aws-3.2.0

- old
+ new

@@ -72,33 +72,32 @@ secret_access_key: config[:aws_secret_access_key], region: config[:aws_region] } end def scheme(queue_name) - "aws.sqs.queue.#{queue_name.tr('-', '_')}.message_count" + 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 + end + def run begin sqs = AWS::SQS.new aws_config if config[:prefix] == '' if config[:queue] == '' critical 'Error, either QUEUE or PREFIX must be specified' end - scheme = if config[:scheme] == '' - scheme config[:queue] - else - config[:scheme] - end - - messages = sqs.queues.named(config[:queue]).approximate_number_of_messages - output scheme, messages + record_queue_metrics(config[:queue], sqs.queues.named(config[:queue])) else sqs.queues.with_prefix(config[:prefix]).each do |q| - queue_name = q.arn.split(':').last - output scheme(queue_name), q.approximate_number_of_messages + record_queue_metrics(q.arn.split(':').last, q) end end rescue => e critical "Error fetching SQS queue metrics: #{e.message}" end