Class: Scout::Server
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- Scout::Server
- Defined in:
- lib/scout_api/server.rb
Instance Attribute Summary collapse
-
#metrics ⇒ Object
readonly
Retrieve metric information.
Class Method Summary collapse
-
.all(options = {}) ⇒ Array
Finds all servers that meets the given conditions.
-
.create(name, options = {}) ⇒ Scout::Server
Creates a new server with the given
name
. -
.delete(id) ⇒ true
Delete a server by
id
. -
.first(id_or_options = nil) ⇒ Scout::Server
Finds the first server that meets the given conditions.
Instance Method Summary collapse
-
#alerts ⇒ Array
Recent alerts for this server.
-
#initialize(hash, ignore = nil) ⇒ Server
constructor
2nd parameter is ignored/a hack because of this open Hashie issue: github.com/intridea/hashie/issues/14.
-
#key ⇒ Object
Returns the key identifier for this server (ex: ‘
6ecad322-0d17-4cb8-9b2c-a12c4541853f
’). -
#plugin(id) ⇒ Scout::Plugin
Details about a specific plugin.
-
#plugins ⇒ Array
Details about all plugins for this server.
-
#triggers ⇒ Array
Details about all triggers for this server.
Constructor Details
#initialize(hash, ignore = nil) ⇒ Server
2nd parameter is ignored/a hack because of this open Hashie issue: github.com/intridea/hashie/issues/14
36 37 38 39 |
# File 'lib/scout_api/server.rb', line 36 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 server.
Scout::Server.metrics
# Metrics with name =~ 'Memory Used' on this server.
Scout::Server.metrics.all(:name => 'Memory Used')
# Average value of metrics with name =~ 'Memory Used' on this server.
Scout::Server.metrics.average(:name => 'Memory Used')
# Maximum value...
Scout::Server.metrics.maximum(:name => 'Memory Used')
# Minimum value...
Scout::Server.metrics.minimum(:name => 'Memory Used')
# Sum metrics, then take average
Scout::Server.metrics.average(:name => 'request_rate', :aggregate => true)
# Retrieve data starting @ 5 hours ago ending at 2 hours ago
Scout::Server.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::Server.metrics.average(:name => 'Memory Used').to_array
# A Url to a Google Sparkline Chart.
Scout::Server.metrics.average(:name => 'Memory Used').to_sparkline
33 34 35 |
# File 'lib/scout_api/server.rb', line 33 def metrics @metrics end |
Class Method Details
.all(options = {}) ⇒ Array
Finds all servers that meets the given conditions. Possible parameter formats:
Scout::Server.all(:name => 'db slaves')
Scout::Server.all(:host => 'web*.geocities')
For the :name
and :host
options, a MySQL-formatted Regex can be used.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/scout_api/server.rb', line 96 def self.all( = {}) if name=[:name] response = Scout::Account.get("/clients.xml?name=#{CGI.escape(name)}") elsif host=[:host] response = Scout::Account.get("/clients.xml?host=#{CGI.escape(host)}") elsif name=[:group_name] response = Scout::Account.get("/clients.xml?group_name=#{CGI.escape(name)}") elsif .empty? response = Scout::Account.get("/clients.xml") else raise Scout::Error, "Invalid finder condition" end response['clients'] ? response['clients'].map { |client| Scout::Server.new(client) } : Array.new end |
.create(name, options = {}) ⇒ Scout::Server
118 119 120 121 122 123 124 125 |
# File 'lib/scout_api/server.rb', line 118 def self.create(name, = {}) id = [:id] response = Scout::Account.post("/#{Scout::Account.param}/clients.xml", :query => {:client => {:name => name, :copy_plugins_from_client_id => id}, :api_version => Scout::VERSION}) raise Scout::Error, response['errors']['error'] if response['errors'] first(response.headers['id'].to_i) end |
.delete(id) ⇒ true
Delete a server by id
. If an error occurs, a [Scout::Error] is raised.
# Delete server w/id=1
ScoutScout::Server.delete(1)
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/scout_api/server.rb', line 133 def self.delete(id) response = Scout::Account.delete("/#{Scout::Account.param}/clients/#{id}.xml?api_version=#{Scout::VERSION}") if response.headers['status'].match('404') raise Scout::Error, "Server Not Found" elsif !response.headers['status'].match('200') raise Scout::Error, "An error occured" else return true end end |
.first(id_or_options = nil) ⇒ Scout::Server
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/scout_api/server.rb', line 59 def self.first( = nil) if .nil? response = Scout::Account.get("/clients.xml?limit=1") Scout::Server.new(response['clients'].first) elsif .is_a?(Hash) if name=[:name] response = Scout::Account.get("/clients.xml?name=#{CGI.escape(name)}") raise Scout::Error, 'Not Found' if response['clients'].nil? Scout::Server.new(response['clients'].first) elsif host=[:host] response = Scout::Account.get("/clients.xml?host=#{CGI.escape(host)}") raise Scout::Error, 'Not Found' if response['clients'].nil? Scout::Server.new(response['clients'].first) else raise Scout::Error, "Invalid finder condition" end elsif .is_a?(Fixnum) response = Scout::Account.get("/clients/#{}.xml") Scout::Server.new(response['client']) elsif .is_a?(String) warn "Server#first(hostname) will be deprecated. Use Server#first(:host => hostname)" response = Scout::Account.get("/clients.xml?host=#{CGI.escape()}") raise Scout::Error, 'Not Found' if response['clients'].nil? Scout::Server.new(response['clients'].first) else raise Scout::Error, "Invalid finder condition" end end |
Instance Method Details
#alerts ⇒ Array
Recent alerts for this server
148 149 150 151 |
# File 'lib/scout_api/server.rb', line 148 def alerts response = Scout::Account.get("/clients/#{self.id}/activities.xml") response['alerts'].map { |alert| decorate_with_server(Scout::Alert.new(alert)) } end |
#key ⇒ Object
Returns the key identifier for this server (ex: ‘6ecad322-0d17-4cb8-9b2c-a12c4541853f
’).
Ruby 1.9.2 Hash#key is a method. This overrides so key
returns Server#key.
44 45 46 |
# File 'lib/scout_api/server.rb', line 44 def key #:nodoc: self[:key] end |
#plugin(id) ⇒ Scout::Plugin
Details about a specific plugin
164 165 166 167 |
# File 'lib/scout_api/server.rb', line 164 def plugin(id) response = Scout::Account.get("/clients/#{self.id}/plugins/#{id}.xml") decorate_with_server(Scout::Plugin.new(response['plugin'])) end |