Class: Scout::Group
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- Scout::Group
- 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
-
#metrics ⇒ Object
readonly
Retrieve metric information.
Class Method Summary collapse
-
.all(options = {}) ⇒ Array
Finds all groups that meets the given conditions.
-
.first(id_or_options = nil) ⇒ Scout::Group
Finds the first group that meets the given conditions.
Instance Method Summary collapse
-
#initialize(hash, ignore = nil) ⇒ Group
constructor
2nd parameter is ignored/a hack because of this open Hashie issue: github.com/intridea/hashie/issues/14.
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
#metrics ⇒ Object (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.
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/scout_api/group.rb', line 80 def self.all( = {}) if name=[:name] response = Scout::Account.get("/groups.xml?name=#{CGI.escape(name)}") elsif .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
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( = nil) if .nil? response = Scout::Account.get("/groups.xml?limit=1") Scout::Group.new(response['groups'].first) elsif .is_a?(Hash) if name=[: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 .is_a?(Fixnum) response = Scout::Account.get("/groups/#{}.xml") Scout::Group.new(response['group']) else raise Scout::Error, "Invalid finder condition" end end |