Sha256: e6f4c81d124b15052aea566a00dd936fcb4c033a010f2673b73824b33e68fef1

Contents?: true

Size: 1.81 KB

Versions: 3

Compression:

Stored size: 1.81 KB

Contents

#! /usr/bin/env ruby
#
#   etcd-metrics
#
# DESCRIPTION:
#   This plugin pulls stats out of an etcd node
#
# OUTPUT:
#    metric data
#
# PLATFORMS:
#   Linux
#
# DEPENDENCIES:
#   gem: sensu-plugin
#   gem: etcd
#
# USAGE:
#   #YELLOW
#
# NOTES:
#
# LICENSE:
#   Copyright (c) 2014, Sean Clerkin
#   Released under the same terms as Sensu (the MIT license); see LICENSE
#   for details.
#

require 'sensu-plugin/metric/cli'
require 'etcd'
require 'socket'

#
# Etcd Metrics
#
class EtcdMetrics < Sensu::Plugin::Metric::CLI::Graphite
  option :scheme,
         description: 'Metric naming scheme',
         short: '-s SCHEME',
         long: '--scheme SCHEME',
         default: "#{Socket.gethostname}.etcd"

  option :etcd_host,
         description: 'Etcd host, defaults to localhost',
         short: '-h HOST',
         long: '--host HOST',
         default: 'localhost'

  option :etcd_port,
         description: 'Etcd port, defaults to 2379',
         short: '-p PORT',
         long: '--port PORT',
         default: '2379'

  option :leader_stats,
         description: 'Show leader stats',
         short: '-l',
         long: '--leader-stats',
         boolean: true,
         default: false

  def run # rubocop:disable all
    client = Etcd.client(host: config[:etcd_host], port: config[:etcd_port])
    client.stats(:self).each do |k, v|
      output([config[:scheme], 'self', k].join('.'), v) if v.is_a? Integer
    end
    client.stats(:store).each do |k, v|
      output([config[:scheme], 'store', k].join('.'), v)
    end
    if config[:leader_stats]
      client.stats(:leader)['followers'].each do |follower, fv|
        fv.each do |metric, mv|
          mv.each do |submetric, sv|
            output([config[:scheme], 'leader', follower, metric, submetric].join('.'), sv)
          end
        end
      end
    end
    ok
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sensu-plugins-etcd-0.1.0 bin/metrics-etcd.rb
sensu-plugins-etcd-0.0.3 bin/metrics-etcd.rb
sensu-plugins-etcd-0.0.2 bin/metrics-etcd.rb