Sha256: 96542f8ea75d0b6fd82157bee33abb6127c080fd412a8b3a0d42c076e63cbd63

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 KB

Contents

#!/usr/bin/env ruby
Process.setproctitle($0)

# Gathers load balancer statistics from Cloudant.com (shared cluster) and submits them to Riemann.

require File.expand_path('../../lib/riemann/tools', __FILE__)

class Riemann::Tools::Cloudant
  include Riemann::Tools
  require 'net/http'
  require 'json'

  opt :cloudant_username, "Cloudant username", :type => :string, :required => true
  opt :cloudant_password, "Cloudant pasword", :type => :string, :required => true

  def tick
    json = JSON.parse(get_json().body)
    json.each do |node|
      return if node['svname'] == 'BACKEND' # this is just a sum of all nodes.

      ns = "cloudant #{node['pxname']}"
      cluster_name = node['tracked'].split('.')[0] # ie: meritage.cloudant.com

      # report health of each node.
      report(
        :service => ns,
        :state   => (node['status'] == 'UP' ? 'ok' : 'critical'),
        :tags    => ['cloudant', cluster_name]
      )

      # report property->metric of each node.
      node.each do |property, metric|
        unless ['pxname', 'svname', 'status', 'tracked'].include?(property)
          report(
            :host    => node['tracked'],
            :service => "#{ns} #{property}",
            :metric  => metric.to_f,
            :state   => (node['status'] == 'UP' ? 'ok' : 'critical'),
            :tags    => ['cloudant', cluster_name]
          )
        end
      end

    end
  end

   def get_json
    http = Net::HTTP.new('cloudant.com', 443)
    http.use_ssl = true
      http.start do |h|
        get = Net::HTTP::Get.new('/api/load_balancer')
        get.basic_auth opts[:cloudant_username], opts[:cloudant_password]
        h.request get
     end
   end

end

Riemann::Tools::Cloudant.run

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
riemann-tools-1.0.0 bin/riemann-cloudant