Class: ScoutScout::Cluster
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- ScoutScout::Cluster
- Defined in:
- lib/scout_scout/cluster.rb
Class Method Summary collapse
-
.average(descriptor, options = {}) ⇒ ScoutScout::Metric
Find the average value of a descriptor by name (ex: ‘last_minute’).
- .calculate(function, descriptor, options = {}) ⇒ Object
-
.format_times(options) ⇒ Object
API expects times in epoch.
-
.maximum(descriptor, options = {}) ⇒ ScoutScout::Metric
Find the maximum value of a descriptor by name (ex: ‘last_minute’).
-
.minimum(descriptor, options = {}) ⇒ ScoutScout::Metric
Find the minimum value of a descriptor by name (ex: ‘last_minute’).
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)
28 29 30 |
# File 'lib/scout_scout/cluster.rb', line 28 def self.average(descriptor, = {}) calculate('AVG',descriptor,) 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, = {}) consolidate = [:per_server] ? 'AVG' : 'SUM' start_time,end_time=format_times() response = ScoutScout.get("/#{ScoutScout.account}/data/value?descriptor=#{CGI.escape(descriptor)}&function=#{function}&consolidate=#{consolidate}&host=#{[: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() .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.
37 38 39 |
# File 'lib/scout_scout/cluster.rb', line 37 def self.maximum(descriptor, = {}) calculate('MAX',descriptor,) end |
.minimum(descriptor, options = {}) ⇒ ScoutScout::Metric
Find the minimum value of a descriptor by name (ex: ‘last_minute’).
See average
for options and examples.
46 47 48 |
# File 'lib/scout_scout/cluster.rb', line 46 def self.minimum(descriptor, = {}) calculate('MIN',descriptor,) end |