Class: ScoutScout::Cluster

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/scout_scout/cluster.rb

Class Method Summary collapse

Class Method Details

.average(descriptor, options = {}) ⇒ ScoutScout::Metric

Find the average value of a descriptor by name (ex: ‘last_minute’). If the descriptor couldn’t be found AND/OR hasn’t reported since options[:start], a ScoutScout::Error is raised.

Options:

  • :host: Only selects descriptors from servers w/hostnames matching this pattern. Use a MySQL-formatted Regex. dev.mysql.com/doc/refman/5.0/en/regexp.html

  • :start: The start time for grabbing metrics. Default is 1 hour ago. Times will be converted to UTC.

  • :end: The end time for grabbing metrics. Default is NOW. Times will be converted to UTC.

  • :per_server: Whether the result should be returned per-server or an aggregate of the entire cluster. Default is false. Note that total is not necessary equal to the value on each server * num of servers.

Examples:

How much memory are my servers using? ScoutScout::Cluster.average(‘mem_used’)

What is the average per-server load on my servers? ScoutScout::Cluster.average(‘cpu_last_minute’, :per_server => true)

How much disk space is available on our db servers? ScoutScout::Cluster.average(‘disk_avail’,:host => “db*.awesomeapp.com”)

How much memory did my servers use yesterday? ScoutScout::Cluster.average(‘mem_used’, :start => Time.now-(24*60*60)*2, :end => Time.now-(24*60*60)*2)

Returns:



28
29
30
# File 'lib/scout_scout/cluster.rb', line 28

def self.average(descriptor,options = {})
  calculate('AVG',descriptor,options)
end

.calculate(function, descriptor, options = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/scout_scout/cluster.rb', line 50

def self.calculate(function,descriptor,options = {})
  consolidate = options[:per_server] ? 'AVG' : 'SUM'
  start_time,end_time=format_times(options)
  response = ScoutScout.get("/#{ScoutScout.}/data/value?descriptor=#{CGI.escape(descriptor)}&function=#{function}&consolidate=#{consolidate}&host=#{options[:host]}&start=#{start_time}&end=#{end_time}")

  if response['data']
    ScoutScout::Metric.new(response['data'])
  else
    raise ScoutScout::Error, response['error']
  end
end

.format_times(options) ⇒ Object

API expects times in epoch.



63
64
65
# File 'lib/scout_scout/cluster.rb', line 63

def self.format_times(options)
  options.values_at(:start,:end).map { |t| t ? t.to_i : nil }
end

.maximum(descriptor, options = {}) ⇒ ScoutScout::Metric

Find the maximum value of a descriptor by name (ex: ‘last_minute’).

See average for options and examples.

Returns:



37
38
39
# File 'lib/scout_scout/cluster.rb', line 37

def self.maximum(descriptor,options = {})
  calculate('MAX',descriptor,options)
end

.minimum(descriptor, options = {}) ⇒ ScoutScout::Metric

Find the minimum value of a descriptor by name (ex: ‘last_minute’).

See average for options and examples.

Returns:



46
47
48
# File 'lib/scout_scout/cluster.rb', line 46

def self.minimum(descriptor,options = {})
  calculate('MIN',descriptor,options)
end