Class: Scout::Group

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/scout_api/group.rb

Overview

Groups represent a collection of servers. They can be created in the Scout UI to put similar servers together (ex: Web Servers, Database Servers).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, ignore = nil) ⇒ Group

2nd parameter is ignored/a hack because of this open Hashie issue: github.com/intridea/hashie/issues/14



38
39
40
41
# File 'lib/scout_api/group.rb', line 38

def initialize(hash, ignore=nil) #:nodoc:
  @metrics = Scout::MetricProxy.new(self)
  super(hash)
end

Instance Attribute Details

#metricsObject (readonly)

Retrieve metric information. See Metric.average for a list of options for the calculation methods (average, minimum, maximum).

Examples:

# All metrics associated with this group.
Scout::Group.metrics

# Metrics with name =~ 'Memory Used' across all servers in this group.
Scout::Group.metrics.all(:name => 'Memory Used')

# Average value of metrics with name =~ 'Memory Used' across all servers in the group
Scout::Group.metrics.average(:name => 'Memory Used')

# Maximum value ...
Scout::Group.metrics.maximum(:name => 'Memory Used')

# Minimum value ... 
Scout::Group.metrics.minimum(:name => 'Memory Used')

# Sum metrics, then take average
Scout::Group.metrics.average(:name => 'request_rate', :aggregate => true)

# Retrieve data starting @ 5 hours ago ending at 2 hours ago
Scout::Group.metrics.average(:name => 'request_rate', :start => Time.now.utc-5*3600, :end => Time.now.utc-2*3600)

# An array of time series values over the past hour
Scout::Group.metrics.average(:name => 'Memory Used').to_array

# A Url to a Google Sparkline Chart
Scout::Group.metrics.average(:name => 'Memory Used').to_sparkline


35
36
37
# File 'lib/scout_api/group.rb', line 35

def metrics
  @metrics
end

Class Method Details

.all(options = {}) ⇒ Array

Finds all groups that meets the given conditions. Possible parameter formats:

Scout::Group.all
Scout::Group.all(:name => 'web')

For the :name, a MySQL-formatted Regex can be used.

Returns:

  • (Array)

    An array of Scout::Group objects



80
81
82
83
84
85
86
87
88
89
# File 'lib/scout_api/group.rb', line 80

def self.all(options = {})
  if name=options[:name]
    response = Scout::Account.get("/groups.xml?name=#{CGI.escape(name)}")
  elsif options.empty?
    response = Scout::Account.get("/groups.xml")
  else
    raise Scout::Error, "Invalid finder condition"
  end
  response['groups'] ? response['groups'].map { |g| Scout::Group.new(g) } : Array.new
end

.first(id_or_options = nil) ⇒ Scout::Group

Finds the first group that meets the given conditions. Possible parameter formats:

Scout::Group.first
Scout::Group.first(1)
Scout::Group.first(:name => 'db slaves')

For the :name, a MySQL-formatted Regex can be used.

Returns:



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/scout_api/group.rb', line 52

def self.first(id_or_options = nil)
  if id_or_options.nil?
    response = Scout::Account.get("/groups.xml?limit=1")
    Scout::Group.new(response['groups'].first)
  elsif id_or_options.is_a?(Hash)
    if name=id_or_options[:name]
      response = Scout::Account.get("/groups.xml?name=#{CGI.escape(name)}")
      raise Scout::Error, 'Not Found' if response['groups'].nil?
      Scout::Group.new(response['groups'].first)
    else
      raise Scout::Error, "Invalid finder condition"
    end
  elsif id_or_options.is_a?(Fixnum)
    response = Scout::Account.get("/groups/#{id_or_options}.xml")
    Scout::Group.new(response['group'])
  else
    raise Scout::Error, "Invalid finder condition"
  end
end