Sha256: eec204206ac345e49037ac230ccc8ce976173dab5c8ae37780e5a8e8fd88853e

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

#!/usr/bin/env ruby
#  encoding: UTF-8
#
# RabbitMQ Exchange Metrics
# ===
#
# DESCRIPTION:
# This plugin gathers by default all the available exchange metrics.
# The list of gathered metrics can also be specified with an option
#
# Code mostly copied from metrics-rabbitmq-queue
#
# PLATFORMS:
#   Linux, BSD, Solaris
#
# DEPENDENCIES:
#   RabbitMQ rabbitmq_management plugin
#   gem: sensu-plugin
#   gem: carrot-top
#
# LICENSE:
# Copyright 2017 Romain Thouvenin <romain@thouvenin.pro>
#
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.

require 'sensu-plugins-rabbitmq'

# main plugin class
class RabbitMQExchangeMetrics < Sensu::Plugin::RabbitMQ::Metrics
  option :filter,
         description: 'Regular expression for filtering exchanges',
         long: '--filter REGEX'

  option :metrics,
         description: 'Regular expression for filtering metrics in each exchange',
         long: '--metrics REGEX'

  def run
    timestamp = Time.now.to_i
    acquire_rabbitmq_info(:exchanges).each do |exchange|
      if config[:filter]
        next unless exchange['name'].match(config[:filter])
      end

      metrics = dotted_keys(exchange)
      metrics.each do |metric|
        if config[:metrics]
          next unless metric.match(config[:metrics])
        end
        value = exchange.dig(*metric.split('.'))
        output("#{config[:scheme]}.#{exchange['name']}.#{metric}", value, timestamp) unless value.nil?
      end
    end

    ok
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sensu-plugins-rabbitmq-3.6.0 bin/metrics-rabbitmq-exchange.rb
sensu-plugins-rabbitmq-3.5.0 bin/metrics-rabbitmq-exchange.rb