Class: Riemann::Tools::Cloudant

Inherits:
Object
  • Object
show all
Includes:
Riemann::Tools
Defined in:
lib/riemann/tools/cloudant.rb

Constant Summary

Constants included from Riemann::Tools

VERSION

Instance Attribute Summary

Attributes included from Riemann::Tools

#argv

Instance Method Summary collapse

Methods included from Riemann::Tools

#attributes, #endpoint_name, included, #initialize, #options, #report, #riemann, #run

Instance Method Details

#jsonObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/riemann/tools/cloudant.rb', line 47

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

#tickObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/riemann/tools/cloudant.rb', line 18

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