Sha256: b9ccb7e3fcb3835af4749fa6d5726128ca7ad976c70543c6b7f9c0dc2f1db433
Contents?: true
Size: 1.93 KB
Versions: 9
Compression:
Stored size: 1.93 KB
Contents
# frozen_string_literal: true require 'riemann/tools' require 'riemann/tools/version' # Gathers load balancer statistics from Cloudant.com (shared cluster) and submits them to Riemann. module Riemann module Tools class 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 opt :user_agent, 'User-Agent header for HTTP requests', short: :none, default: "#{File.basename($PROGRAM_NAME)}/#{Riemann::Tools::VERSION} (+https://github.com/riemann/riemann-tools)" def tick json.each do |node| break 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| next if %w[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 def json http = ::Net::HTTP.new('cloudant.com', 443) http.use_ssl = true http.start do |h| get = ::Net::HTTP::Get.new('/api/load_balancer', { 'user-agent' => opts[:user_agent] }) get.basic_auth opts[:cloudant_username], opts[:cloudant_password] h.request get end JSON.parse(http.boby) end end end end
Version data entries
9 entries across 9 versions & 1 rubygems