Class: Rubix::ClusterMonitor

Inherits:
ChefMonitor show all
Defined in:
lib/rubix/monitors/cluster_monitor.rb

Overview

A generic monitor class for constructing Zabbix monitors that monitor whole clusters.

This class handles the low-level logic of finding a set of nodes and then grouping them by cluster.

It’s still up to a subclass to determine how to make a measurement on the cluster.

Here’s an example of a script which finds the average uptime of nodes a value of ‘bar’ set for property ‘foo’, grouped by cluster.

#!/usr/bin/env ruby
# in cluster_uptime_monitor

class ClusterUptimeMonitor < Rubix::ClusterMonitor

  def node_query
    'role:nginx'
  end

  def measure_cluster cluster_name
    total_seconds = nodes_by_cluster[cluster_name].inject(0.0) do |sum, node|
      sum += node['uptime_seconds']
    end
    average_uptime = total_seconds.to_f / nodes_by_cluster[cluster_name].size.to_f
    write(:hostname => 'cluster_name') do |data|
      data << ['uptime.average', average_uptime]
    end
  end
end

ClusterUptimeMonitor.run if $0 == __FILE__

See documentation for Rubix::Monitor to understand how to run this script.

Direct Known Subclasses

ESMonitor, HBaseMonitor, MongoMonitor

Instance Attribute Summary collapse

Attributes inherited from Monitor

#settings

Instance Method Summary collapse

Methods inherited from ChefMonitor

#chef_node_from_node_name, #chef_node_name_from_ip, default_settings, #search_nodes, #set_chef_credentials

Methods inherited from Monitor

#close, default_settings, #fifo?, #file?, #loop?, #loop_period, #output, #output_path, run, #run, #stdout?, #write

Constructor Details

#initialize(settings) ⇒ ClusterMonitor

Returns a new instance of ClusterMonitor.



43
44
45
46
# File 'lib/rubix/monitors/cluster_monitor.rb', line 43

def initialize settings
  super(settings)
  group_nodes_by_cluster
end

Instance Attribute Details

#nodes_by_clusterObject (readonly)

Returns the value of attribute nodes_by_cluster.



41
42
43
# File 'lib/rubix/monitors/cluster_monitor.rb', line 41

def nodes_by_cluster
  @nodes_by_cluster
end

#private_ips_by_clusterObject (readonly)

Returns the value of attribute private_ips_by_cluster.



41
42
43
# File 'lib/rubix/monitors/cluster_monitor.rb', line 41

def private_ips_by_cluster
  @private_ips_by_cluster
end

Instance Method Details

#clustersObject



68
69
70
# File 'lib/rubix/monitors/cluster_monitor.rb', line 68

def clusters
  private_ips_by_cluster.keys
end

#group_nodes_by_clusterObject



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rubix/monitors/cluster_monitor.rb', line 56

def group_nodes_by_cluster
  @private_ips_by_cluster = {}
  @nodes_by_cluster       = {}
  matching_chef_nodes.first.each do |node|
    @nodes_by_cluster[node['cluster_name']] ||= []
    @nodes_by_cluster[node['cluster_name']] << node
    
    @private_ips_by_cluster[node['cluster_name']] ||= []
    @private_ips_by_cluster[node['cluster_name']] << node['ipaddress']
  end
end

#matching_chef_nodesObject



52
53
54
# File 'lib/rubix/monitors/cluster_monitor.rb', line 52

def matching_chef_nodes
  search_nodes(node_query)
end

#measureObject



72
73
74
75
76
# File 'lib/rubix/monitors/cluster_monitor.rb', line 72

def measure
  clusters.each do |cluster_name|
    measure_cluster(cluster_name)
  end
end

#measure_cluster(cluster_name) ⇒ Object

Raises:

  • (NotImplementedError)


78
79
80
# File 'lib/rubix/monitors/cluster_monitor.rb', line 78

def measure_cluster cluster_name
  raise NotImplementedError.new("Override the 'measure_cluster' method to make measurements of a given cluster.")
end

#node_queryObject



48
49
50
# File 'lib/rubix/monitors/cluster_monitor.rb', line 48

def node_query
  ''
end