-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from perezd/riemann-cloudant
adds Cloudant.com shared cluster load balancer statistics/monitoring support
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |