Class: HttpAvailabilityMonitor

Inherits:
Rubix::Monitor show all
Includes:
Rubix::ChefMonitor, Rubix::ClusterMonitor, Rubix::ZabbixMonitor
Defined in:
lib/rubix/examples/simple_chef_monitor.rb,
lib/rubix/examples/simple_zabbix_monitor.rb,
lib/rubix/examples/simple_cluster_monitor.rb

Constant Summary

Constants included from Rubix::ClusterMonitor

Rubix::ClusterMonitor::DEFAULT_CLUSTER

Instance Attribute Summary

Attributes included from Rubix::ClusterMonitor

#hosts_by_cluster

Attributes inherited from Rubix::Monitor

#settings

Instance Method Summary collapse

Methods included from Rubix::ClusterMonitor

#cluster_name_from_host, #clusters, #default_cluster, #group_hosts_by_cluster, #initialize

Methods included from Rubix::ZabbixMonitor

#connect_to_zabbix, #hosts, included, #template_name

Methods included from Rubix::ChefMonitor

#chef_node_from_ip, #chef_node_from_node_name, #chef_node_name_from_ip, included, #initialize, #search_nodes, #set_chef_credentials

Methods inherited from Rubix::Monitor

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

Instance Method Details

#chef_nodeObject



14
15
16
17
18
19
20
# File 'lib/rubix/examples/simple_chef_monitor.rb', line 14

def chef_node
  begin
    @chef_node ||= chef_node_from_node_name(Chef::Config[:node_name])
  rescue => e
    puts "Could not find a Chef node named #{Chef::Config[:node_name]} -- are you sure your Chef settings are correct?"
  end
end

#host_group_nameObject



14
15
16
# File 'lib/rubix/examples/simple_zabbix_monitor.rb', line 14

def host_group_name
  'Zabbix servers'
end

#measureObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rubix/examples/simple_chef_monitor.rb', line 22

def measure
  begin
    timeout(1) do
      if Net::HTTP.get_response(URI.parse("http://#{chef_node['fqdn']}/")).code.to_i == 200
        write [host.name, 'webserver.available', 1]
        return
      end
    end
  rescue => e
    puts e.message
  end
  write [host.name, 'webserver.available', 0]
end

#measure_cluster(cluster_name) ⇒ Object



19
20
21
22
23
24
# File 'lib/rubix/examples/simple_cluster_monitor.rb', line 19

def measure_cluster cluster_name
  hosts_by_cluster[cluster_name].each do |host|
    measure_host(host)
  end
  write [cluster_name, 'something', 1]
end

#measure_host(host) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rubix/examples/simple_zabbix_monitor.rb', line 24

def measure_host host
  begin
    timeout(1) do
      if Net::HTTP.get_response(URI.parse("http://#{host.ip}/")).code.to_i == 200
        write [host.name, 'webserver.available', 1]
        return
      end
    end
  rescue => e
    puts e.message
  end
  write [host.name, 'webserver.available', 0]
end