Skip to content

Commit

Permalink
Merge pull request #7 from perezd/riemann-cloudant
Browse files Browse the repository at this point in the history
adds Cloudant.com shared cluster load balancer statistics/monitoring support
  • Loading branch information
aphyr committed Oct 22, 2012
2 parents b89a4db + ce05d97 commit 7cd10d6
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions bin/riemann-cloudant
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env ruby

# 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']} #{node['tracked']}"
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(
: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

0 comments on commit 7cd10d6

Please sign in to comment.