Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds Cloudant.com shared cluster load balancer statistics/monitoring support #7

Merged
merged 1 commit into from
Oct 22, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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