scout_scout 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,28 +1,52 @@
1
1
  = scout_scout
2
2
 
3
- Scout your data out of Scout:
4
-
5
- require 'scout_scout'
6
- scout = ScoutScout.new('youraccountname', 'your@awesome.com', 'sekret')
7
- #all your servers
8
- clients = scout.clients
9
- #one specific server - pass in hostname
10
- ram_hungry = ScoutScout::Client.find('db1.awesome.com')
11
- #details on that server's plugins
12
- ram_hungry_plugins = ram_hungry.plugins
13
- #details about a specific plugin
14
- data = ram_hungry.plugin(12345)
3
+ A library for extracting data out of Scout[http//:scoutapp.com], a hosted monitoring service. This is experimental and likely to change.
4
+
5
+ require 'scout_scout'
6
+ scout = ScoutScout.new('youraccountname', 'your@awesome.com', 'sekret')
7
+
8
+ #all your servers
9
+ servers = scout.servers
10
+
11
+ #one specific server - pass in hostname
12
+ ram_hungry = ScoutScout::Server.first('db1.awesome.com')
13
+
14
+ #all servers that match the hostname.
15
+ # see mysql regex formatting: http://dev.mysql.com/doc/refman/5.0/en/regexp.html
16
+ app_servers = ScoutScout::Server.all(:host => 'db[0-9]*.awesome.com')
17
+
18
+ #details on that server's plugins
19
+ ram_hungry_plugins = ram_hungry.plugins
20
+
21
+ #details about a specific plugin
22
+ data = ram_hungry.plugin(12345)
23
+
24
+ #all available descriptors
25
+ descriptors = ScoutScout::Descriptor.all
26
+
27
+ # all descriptors on servers that match the provided host
28
+ descriptors = ScoutScout::Descriptor.all(:host => 'awesome.com')
29
+
30
+ #cluster metrics
31
+ ScoutScout::Cluster.average('mem_used')
32
+
33
+ == Metrics
34
+
35
+ The library allows you to extract aggregate metrics across all and/or
36
+ selected servers in your account. See <tt>Cluster#average</tt> for
37
+ information and examples.
15
38
 
16
39
  == Note on Patches/Pull Requests
17
-
40
+
18
41
  * Fork the project.
19
42
  * Make your feature addition or bug fix.
20
43
  * Add tests for it. This is important so I don't break it in a
21
44
  future version unintentionally.
22
45
  * Commit, do not mess with rakefile, version, or history.
23
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
46
+ (if you want to have your own version, that is fine but bump version in a
47
+ commit by itself I can ignore when I pull)
24
48
  * Send me a pull request. Bonus points for topic branches.
25
49
 
26
50
  == Copyright
27
51
 
28
- Copyright (c) 2010 Jesse Newland. See LICENSE for details.
52
+ Copyright (c) 2010 Jesse Newland, Derek Haynes. See LICENSE for details.
data/Rakefile CHANGED
@@ -49,3 +49,8 @@ Rake::RDocTask.new do |rdoc|
49
49
  rdoc.rdoc_files.include('README*')
50
50
  rdoc.rdoc_files.include('lib/**/*.rb')
51
51
  end
52
+
53
+ desc "Open an irb session preloaded with this library"
54
+ task :console do
55
+ sh "irb -rubygems -I lib -r scout_scout.rb"
56
+ end
@@ -1,23 +1,29 @@
1
1
  require 'hashie'
2
2
  require 'httparty'
3
+ require 'cgi'
3
4
  require 'scout_scout/version'
4
- require 'scout_scout/client'
5
+ require 'scout_scout/server'
5
6
  require 'scout_scout/descriptor'
6
7
  require 'scout_scout/plugin'
7
8
  require 'scout_scout/alert'
9
+ require 'scout_scout/cluster.rb'
10
+ require 'scout_scout/metric.rb'
8
11
 
9
12
  class ScoutScout
10
13
  include HTTParty
11
14
  base_uri 'https://scoutapp.com'
12
15
  format :xml
13
16
  mattr_inheritable :account
17
+
18
+ class Error < RuntimeError
19
+ end
14
20
 
15
21
  def initialize(scout_account_name, username, password)
16
22
  self.class.account = scout_account_name
17
23
  self.class.basic_auth username, password
18
24
  end
19
25
 
20
- # Recent alerts across all clients on this account
26
+ # Recent alerts across all servers on this account
21
27
  #
22
28
  # @return [Array] An array of ScoutScout::Alert objects
23
29
  def alerts
@@ -25,12 +31,25 @@ class ScoutScout
25
31
  response['alerts'].map { |alert| ScoutScout::Alert.new(alert) }
26
32
  end
27
33
 
28
- # All clients on this account
34
+ # All servers on this account
29
35
  #
30
- # @return [Array] An array of ScoutScout::Client objects
31
- def clients
36
+ # @return [Array] An array of ScoutScout::Server objects
37
+ def servers
32
38
  response = self.class.get("/#{self.class.account}/clients.xml")
33
- response['clients'].map { |client| ScoutScout::Client.new(client) }
39
+ response['clients'].map { |client| ScoutScout::Server.new(client) }
40
+ end
41
+
42
+ class << self
43
+ alias_method :http_get, :get
44
+ end
45
+
46
+ # Checks for errors via the HTTP status code. If an error is found, a
47
+ # ScoutScout::Error is raised. Otherwise, the response.
48
+ #
49
+ # @return HTTParty::Response
50
+ def self.get(uri)
51
+ response = http_get(uri)
52
+ response.code.to_s =~ /^(4|5)/ ? raise( ScoutScout::Error,response.message) : response
34
53
  end
35
54
 
36
55
  end
@@ -1,15 +1,17 @@
1
1
  class ScoutScout::Alert < Hashie::Mash
2
- # The Scout client that generated this alert
2
+ attr_writer :server
3
+
4
+ # The Scout server that generated this alert
3
5
  #
4
- # @return [ScoutScout::Client]
5
- def client
6
- @client ||= ScoutScout::Client.find(client_id)
6
+ # @return [ScoutScout::Server]
7
+ def server
8
+ @server ||= ScoutScout::Server.first(client_id)
7
9
  end
8
10
 
9
11
  # The Scout plugin that generated this alert
10
12
  #
11
13
  # @return [ScoutScout::Plugin]
12
14
  def plugin
13
- client.plugin(plugin_id)
15
+ server.plugin(plugin_id)
14
16
  end
15
17
  end
@@ -0,0 +1,66 @@
1
+ class ScoutScout::Cluster < Hashie::Mash
2
+ # Find the average value of a descriptor by name (ex: 'last_minute'). If the descriptor couldn't be found AND/OR
3
+ # hasn't reported since +options[:start]+, a ScoutScout::Error is raised.
4
+ #
5
+ # Options:
6
+ #
7
+ # * <tt>:host</tt>: Only selects descriptors from servers w/hostnames matching this pattern.
8
+ # Use a MySQL-formatted Regex. http://dev.mysql.com/doc/refman/5.0/en/regexp.html
9
+ # * <tt>:start</tt>: The start time for grabbing metrics. Default is 1 hour ago. Times will be converted to UTC.
10
+ # * <tt>:end</tt>: The end time for grabbing metrics. Default is NOW. Times will be converted to UTC.
11
+ # * <tt>:per_server</tt>: Whether the result should be returned per-server or an aggregate of the entire cluster.
12
+ # Default is false. Note that total is not necessary equal to the value on each server * num of servers.
13
+ # Examples:
14
+ #
15
+ # How much memory are my servers using?
16
+ # ScoutScout::Cluster.average('mem_used')
17
+ #
18
+ # What is the average per-server load on my servers?
19
+ # ScoutScout::Cluster.average('cpu_last_minute', :per_server => true)
20
+ #
21
+ # How much disk space is available on our db servers?
22
+ # ScoutScout::Cluster.average('disk_avail',:host => "db[0-9]*.awesomeapp.com")
23
+ #
24
+ # How much memory did my servers use yesterday?
25
+ # ScoutScout::Cluster.average('mem_used', :start => Time.now-(24*60*60)*2, :end => Time.now-(24*60*60)*2)
26
+ #
27
+ # @return [ScoutScout::Metric]
28
+ def self.average(descriptor,options = {})
29
+ calculate('AVG',descriptor,options)
30
+ end
31
+
32
+ # Find the maximum value of a descriptor by name (ex: 'last_minute').
33
+ #
34
+ # See +average+ for options and examples.
35
+ #
36
+ # @return [ScoutScout::Metric]
37
+ def self.maximum(descriptor,options = {})
38
+ calculate('MAX',descriptor,options)
39
+ end
40
+
41
+ # Find the minimum value of a descriptor by name (ex: 'last_minute').
42
+ #
43
+ # See +average+ for options and examples.
44
+ #
45
+ # @return [ScoutScout::Metric]
46
+ def self.minimum(descriptor,options = {})
47
+ calculate('MIN',descriptor,options)
48
+ end
49
+
50
+ def self.calculate(function,descriptor,options = {})
51
+ consolidate = options[:per_server] ? 'AVG' : 'SUM'
52
+ start_time,end_time=format_times(options)
53
+ response = ScoutScout.get("/#{ScoutScout.account}/data/value?descriptor=#{CGI.escape(descriptor)}&function=#{function}&consolidate=#{consolidate}&host=#{options[:host]}&start=#{start_time}&end=#{end_time}")
54
+
55
+ if response['data']
56
+ ScoutScout::Metric.new(response['data'])
57
+ else
58
+ raise ScoutScout::Error, response['error']
59
+ end
60
+ end
61
+
62
+ # API expects times in epoch.
63
+ def self.format_times(options)
64
+ options.values_at(:start,:end).map { |t| t ? t.to_i : nil }
65
+ end
66
+ end
@@ -1,2 +1,40 @@
1
1
  class ScoutScout::Descriptor < Hashie::Mash
2
+ attr_accessor :server, :plugin
3
+
4
+ # Search for descriptors by matching name and hostname.
5
+ #
6
+ # Options:
7
+ #
8
+ # - :descriptor => The descriptor name to match
9
+ # - :host => The host name to match
10
+ #
11
+ # @return [Array] An array of ScoutScout::Descriptor objects
12
+ def self.all(options = {})
13
+ response = ScoutScout.get("/#{ScoutScout.account}/descriptors.xml?descriptor=#{CGI.escape(options[:descriptor] || String.new)}&host=#{options[:host]}")
14
+ response['ar_descriptors'] ? response['ar_descriptors'].map { |descriptor| ScoutScout::Descriptor.new(descriptor) } : Array.new
15
+ end
16
+
17
+ # @return [ScoutScout::Metric]
18
+ def average(opts = {})
19
+ ScoutScout::Cluster.average(name, options_for_relationship(opts))
20
+ end
21
+
22
+ # @return [ScoutScout::Metric]
23
+ def maximum(opts = {})
24
+ ScoutScout::Cluster.maximum(name, options_for_relationship(opts))
25
+ end
26
+
27
+ # @return [ScoutScout::Metric]
28
+ def maximum(opts = {})
29
+ ScoutScout::Cluster.maximum(name, options_for_relationship(opts))
30
+ end
31
+
32
+ protected
33
+
34
+ def options_for_relationship(opts = {})
35
+ relationship_options = {}
36
+ relationship_options[:host] = server.hostname if server
37
+ opts.merge(relationship_options)
38
+ end
39
+
2
40
  end
@@ -0,0 +1,2 @@
1
+ class ScoutScout::Metric < Hashie::Mash
2
+ end
@@ -1,4 +1,6 @@
1
1
  class ScoutScout::Plugin < Hashie::Mash
2
+ attr_accessor :server
3
+
2
4
  def initialize(hash)
3
5
  if hash['descriptors'] && hash['descriptors']['descriptor']
4
6
  @descriptor_hash = hash['descriptors']['descriptor']
@@ -11,6 +13,15 @@ class ScoutScout::Plugin < Hashie::Mash
11
13
  #
12
14
  # @return [Array] An array of ScoutScout::Descriptor objects
13
15
  def descriptors
14
- @descriptors ||= @descriptor_hash.map { |d| ScoutScout::Descriptor.new(d) }
16
+ @descriptors ||= @descriptor_hash.map { |d| decorate_with_server_and_plugin(ScoutScout::Descriptor.new(d)) }
15
17
  end
18
+
19
+ protected
20
+
21
+ def decorate_with_server_and_plugin(hashie)
22
+ hashie.server = self.server
23
+ hashie.plugin = self
24
+ hashie
25
+ end
26
+
16
27
  end
@@ -0,0 +1,81 @@
1
+ class ScoutScout::Server < Hashie::Mash
2
+ def initialize(hash)
3
+ if hash['active_alerts']
4
+ @alert_hash = hash['active_alerts']
5
+ hash.delete('active_alerts')
6
+ end
7
+ super(hash)
8
+ end
9
+
10
+ # Search for a server by id or matching hostname
11
+ #
12
+ # @return [ScoutScout::Server]
13
+ def self.first(server_id_or_hostname)
14
+ if server_id_or_hostname.is_a?(Fixnum)
15
+ response = ScoutScout.get("/#{ScoutScout.account}/clients/#{server_id_or_hostname}.xml")
16
+ ScoutScout::Server.new(response['client'])
17
+ else
18
+ response = ScoutScout.get("/#{ScoutScout.account}/clients.xml?host=#{server_id_or_hostname}")
19
+ raise ScoutScout::Error, 'Not Found' if response['clients'].nil?
20
+ ScoutScout::Server.new(response['clients'].first)
21
+ end
22
+ end
23
+
24
+ # Search for servers by matching hostname via :host.
25
+ #
26
+ # Example: ScoutScout::Server.all(:host => 'soawesome.org')
27
+ #
28
+ # @return [Array] An array of ScoutScout::Server objects
29
+ def self.all(options)
30
+ hostname = options[:host]
31
+ raise ScoutScout::Error, "Please specify a host via :host" if hostname.nil?
32
+ response = ScoutScout.get("/#{ScoutScout.account}/clients.xml?host=#{hostname}")
33
+ response['clients'] ? response['clients'].map { |client| ScoutScout::Server.new(client) } : Array.new
34
+ end
35
+
36
+ # Active alerts for this server
37
+ #
38
+ # @return [Array] An array of ScoutScout::Alert objects
39
+ def active_alerts
40
+ @active_alerts ||= @alert_hash.map { |a| decorate_with_server(ScoutScout::Alert.new(a)) }
41
+ end
42
+
43
+ # Recent alerts for this server
44
+ #
45
+ # @return [Array] An array of ScoutScout::Alert objects
46
+ def alerts
47
+ response = ScoutScout.get("/#{ScoutScout.account}/clients/#{self.id}/activities.xml")
48
+ response['alerts'].map { |alert| decorate_with_server(ScoutScout::Alert.new(alert)) }
49
+ end
50
+
51
+ # Details about all plugins for this server
52
+ #
53
+ # @return [Array] An array of ScoutScout::Plugin objects
54
+ def plugins
55
+ response = ScoutScout.get("/#{ScoutScout.account}/clients/#{self.id}/plugins.xml")
56
+ response['plugins'].map { |plugin| decorate_with_server(ScoutScout::Plugin.new(plugin)) }
57
+ end
58
+
59
+ # Details about a specific plugin
60
+ #
61
+ # @return [ScoutScout::Plugin]
62
+ def plugin(id)
63
+ response = ScoutScout.get("/#{ScoutScout.account}/clients/#{self.id}/plugins/#{id}.xml")
64
+ decorate_with_server(ScoutScout::Plugin.new(response['plugin']))
65
+ end
66
+
67
+ # All descriptors for this server
68
+ #
69
+ # @return [Array] An array of ScoutScout::Descriptor objects
70
+ def descriptors
71
+ ScoutScout::Descriptor.all(:host => hostname).map { |d| decorate_with_server(d) }
72
+ end
73
+
74
+ protected
75
+
76
+ def decorate_with_server(hashie)
77
+ hashie.server = self
78
+ hashie
79
+ end
80
+
81
+ end
@@ -1,3 +1,3 @@
1
1
  class ScoutScout
2
- VERSION = '0.0.3'
3
- end
2
+ VERSION = '0.0.4'
3
+ end
@@ -16,6 +16,7 @@
16
16
  <send-checkup-email type="boolean" nil="true"></send-checkup-email>
17
17
  <send-checkup-sms type="boolean" nil="true"></send-checkup-sms>
18
18
  <take-snapshots type="boolean">false</take-snapshots>
19
+ <hostname>foobar.com</hostname>
19
20
  <version>3.2.6</version>
20
21
  <active-alerts type="array"/>
21
22
  </client>
@@ -17,6 +17,7 @@
17
17
  <send-checkup-email type="boolean" nil="true"></send-checkup-email>
18
18
  <send-checkup-sms type="boolean" nil="true"></send-checkup-sms>
19
19
  <take-snapshots type="boolean">false</take-snapshots>
20
+ <hostname>foobar.com</hostname>
20
21
  <version>3.2.6</version>
21
22
  <active-alerts type="array"/>
22
23
  </client>
@@ -37,6 +38,7 @@
37
38
  <send-checkup-email type="boolean" nil="true"></send-checkup-email>
38
39
  <send-checkup-sms type="boolean" nil="true"></send-checkup-sms>
39
40
  <take-snapshots type="boolean">false</take-snapshots>
41
+ <hostname>foo2.com</hostname>
40
42
  <version>5.0.3</version>
41
43
  <active-alerts type="array">
42
44
  <alert>
@@ -0,0 +1,5 @@
1
+ <data>
2
+ <value>31.10</value>
3
+ <label>Cpu last minute</label>
4
+ <units></units>
5
+ </data>
@@ -0,0 +1,93 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <ar-descriptors type="array">
3
+ <ar-descriptor>
4
+ <name>Passenger/apache_private_total</name>
5
+ </ar-descriptor>
6
+ <ar-descriptor>
7
+ <name>Server Overview/cpu_last_fifteen_minutes</name>
8
+ </ar-descriptor>
9
+ <ar-descriptor>
10
+ <name>Server Overview/cpu_last_five_minutes</name>
11
+ </ar-descriptor>
12
+ <ar-descriptor>
13
+ <name>Server Overview/cpu_last_minute</name>
14
+ </ar-descriptor>
15
+ <ar-descriptor>
16
+ <name>Server Overview/disk_avail</name>
17
+ </ar-descriptor>
18
+ <ar-descriptor>
19
+ <name>Server Overview/disk_capacity</name>
20
+ </ar-descriptor>
21
+ <ar-descriptor>
22
+ <name>Server Overview/disk_size</name>
23
+ </ar-descriptor>
24
+ <ar-descriptor>
25
+ <name>Server Overview/disk_used</name>
26
+ </ar-descriptor>
27
+ <ar-descriptor>
28
+ <name>Network Throughput/eth0_in</name>
29
+ </ar-descriptor>
30
+ <ar-descriptor>
31
+ <name>Network Throughput/eth0_in_packets</name>
32
+ </ar-descriptor>
33
+ <ar-descriptor>
34
+ <name>Network Throughput/eth0_out</name>
35
+ </ar-descriptor>
36
+ <ar-descriptor>
37
+ <name>Network Throughput/eth0_out_packets</name>
38
+ </ar-descriptor>
39
+ <ar-descriptor>
40
+ <name>Network Throughput/eth1_in</name>
41
+ </ar-descriptor>
42
+ <ar-descriptor>
43
+ <name>Network Throughput/eth1_in_packets</name>
44
+ </ar-descriptor>
45
+ <ar-descriptor>
46
+ <name>Network Throughput/eth1_out</name>
47
+ </ar-descriptor>
48
+ <ar-descriptor>
49
+ <name>Network Throughput/eth1_out_packets</name>
50
+ </ar-descriptor>
51
+ <ar-descriptor>
52
+ <name>Server Overview/mem_swap_percent</name>
53
+ </ar-descriptor>
54
+ <ar-descriptor>
55
+ <name>Server Overview/mem_swap_total</name>
56
+ </ar-descriptor>
57
+ <ar-descriptor>
58
+ <name>Server Overview/mem_swap_used</name>
59
+ </ar-descriptor>
60
+ <ar-descriptor>
61
+ <name>Server Overview/mem_total</name>
62
+ </ar-descriptor>
63
+ <ar-descriptor>
64
+ <name>Server Overview/mem_used</name>
65
+ </ar-descriptor>
66
+ <ar-descriptor>
67
+ <name>Server Overview/mem_used_percent</name>
68
+ </ar-descriptor>
69
+ <ar-descriptor>
70
+ <name>Passenger/nginx_processes</name>
71
+ </ar-descriptor>
72
+ <ar-descriptor>
73
+ <name>Passenger/passenger_max_pool_size</name>
74
+ </ar-descriptor>
75
+ <ar-descriptor>
76
+ <name>Passenger/passenger_private_total</name>
77
+ </ar-descriptor>
78
+ <ar-descriptor>
79
+ <name>Passenger/passenger_process_active</name>
80
+ </ar-descriptor>
81
+ <ar-descriptor>
82
+ <name>Passenger/passenger_process_current</name>
83
+ </ar-descriptor>
84
+ <ar-descriptor>
85
+ <name>Passenger/passenger_process_inactive</name>
86
+ </ar-descriptor>
87
+ <ar-descriptor>
88
+ <name>Passenger/passenger_queue_depth</name>
89
+ </ar-descriptor>
90
+ <ar-descriptor>
91
+ <name>Passenger/passenger_vmsize_total</name>
92
+ </ar-descriptor>
93
+ </ar-descriptors>
@@ -7,25 +7,25 @@ describe "ScoutScout" do
7
7
  it "should provide a version constant" do
8
8
  ScoutScout::VERSION.should be_instance_of(String)
9
9
  end
10
- it "should set the client and basic auth parameters when initialized" do
10
+ it "should set the server and basic auth parameters when initialized" do
11
11
  @scout_scout.class.account.should == 'account'
12
12
  @scout_scout.class.default_options[:basic_auth].should == { :username => 'username', :password => 'password' }
13
13
  end
14
14
  describe "global" do
15
- describe "client list" do
15
+ describe "server list" do
16
16
  before(:each) do
17
17
  @scout_scout.stub_get('clients.xml')
18
- @clients = @scout_scout.clients
18
+ @servers = @scout_scout.servers
19
19
  end
20
- it 'should list all clients' do
21
- @clients.size.should == 2
20
+ it 'should list all servers' do
21
+ @servers.size.should == 2
22
22
  end
23
- it "should be an array ScoutScout::Client objects" do
24
- @clients.first.class.should == ScoutScout::Client
23
+ it "should be an array ScoutScout::Server objects" do
24
+ @servers.first.class.should == ScoutScout::Server
25
25
  end
26
26
  it "should include active alerts" do
27
- @clients.last.active_alerts.first.class.should == ScoutScout::Alert
28
- @clients.last.active_alerts.first.title.should =~ /Passenger/
27
+ @servers.last.active_alerts.first.class.should == ScoutScout::Alert
28
+ @servers.last.active_alerts.first.title.should =~ /Passenger/
29
29
  end
30
30
  end
31
31
  describe 'alert log' do
@@ -36,9 +36,9 @@ describe "ScoutScout" do
36
36
  it "should be an array ScoutScout::Alert objects" do
37
37
  @activities.first.class.should == ScoutScout::Alert
38
38
  end
39
- it "should be associated with it's plugin and client" do
39
+ it "should be associated with it's plugin and server" do
40
40
  @scout_scout.stub_get('clients/24331.xml', 'client.xml')
41
- @activities.first.client.class.should == ScoutScout::Client
41
+ @activities.first.server.class.should == ScoutScout::Server
42
42
  @scout_scout.stub_get('clients/13431/plugins/122761.xml', 'plugin_data.xml')
43
43
  @activities.first.plugin.class.should == ScoutScout::Plugin
44
44
  end
@@ -49,36 +49,60 @@ describe "ScoutScout" do
49
49
  end
50
50
  end
51
51
  end
52
+ describe 'descriptors' do
53
+ before(:each) do
54
+ @scout_scout.stub_get('descriptors.xml?descriptor=&host=&','descriptors.xml')
55
+ @descriptors = ScoutScout::Descriptor.all
56
+ end
57
+ it "should be an array ScoutScout::Descriptor objects" do
58
+ @descriptors.first.class.should == ScoutScout::Descriptor
59
+ end
60
+ it "should be accessable" do
61
+ @descriptors.size.should == 30
62
+ end
63
+ end
64
+ describe 'descriptor metrics' do
65
+ before(:each) do
66
+ @scout_scout.stub_get('data/value?descriptor=cpu_last_minute&function=AVG&consolidate=SUM&host=&start=&end=&','data.xml')
67
+ @metric = ScoutScout::Cluster.average('cpu_last_minute')
68
+ end
69
+ it "should be a ScoutScout::Metric object" do
70
+ @metric.class.should == ScoutScout::Metric
71
+ end
72
+ it "should contain the value" do
73
+ @metric.value.should == '31.10'
74
+ end
75
+ end
52
76
  end
53
- describe 'individual clients' do
77
+ describe 'individual servers' do
54
78
  describe 'should be accessable' do
55
79
  describe '' do
56
80
  before(:each) do
57
81
  @scout_scout.stub_get('clients/1234.xml', 'client.xml')
58
- @client = ScoutScout::Client.find(1234)
82
+ @server = ScoutScout::Server.first(1234)
59
83
  end
60
84
  it "by id" do
61
- @client.key.should == 'FOOBAR'
62
- @client.class.should == ScoutScout::Client
85
+ @server.key.should == 'FOOBAR'
86
+ @server.class.should == ScoutScout::Server
63
87
  end
64
88
  end
65
89
  describe '' do
66
90
  before(:each) do
67
91
  @scout_scout.stub_get('clients.xml?host=foo.awesome.com', 'client_by_hostname.xml')
68
- @client = ScoutScout::Client.find('foo.awesome.com')
92
+ @server = ScoutScout::Server.first('foo.awesome.com')
69
93
  end
70
94
  it "by hostname" do
71
- @client.key.should == 'FOOBAR'
72
- @client.class.should == ScoutScout::Client
95
+ @server.key.should == 'FOOBAR'
96
+ @server.class.should == ScoutScout::Server
73
97
  end
74
98
  end
75
99
  end
76
100
  describe 'alert log' do
77
101
  before(:each) do
78
102
  @scout_scout.stub_get('clients/13431.xml', 'client.xml')
79
- @client = ScoutScout::Client.find(13431)
103
+ @server = ScoutScout::Server.first(13431)
80
104
  @scout_scout.stub_get('clients/13431/activities.xml', 'activities.xml')
81
- @activities = @client.alerts
105
+ @activities = @server.alerts
82
106
  end
83
107
  it "should be accessable" do
84
108
  @activities.size.should == 2
@@ -94,9 +118,9 @@ describe "ScoutScout" do
94
118
  describe 'list' do
95
119
  before(:each) do
96
120
  @scout_scout.stub_get('clients/13431.xml', 'client.xml')
97
- @client = ScoutScout::Client.find(13431)
121
+ @server = ScoutScout::Server.first(13431)
98
122
  @scout_scout.stub_get('clients/13431/plugins.xml', 'plugins.xml')
99
- @plugins = @client.plugins
123
+ @plugins = @server.plugins
100
124
  end
101
125
  it "should be accessable" do
102
126
  @plugins.size.should == 2
@@ -112,9 +136,9 @@ describe "ScoutScout" do
112
136
  describe 'individually' do
113
137
  before(:each) do
114
138
  @scout_scout.stub_get('clients/13431.xml', 'client.xml')
115
- @client = ScoutScout::Client.find(13431)
139
+ @server = ScoutScout::Server.first(13431)
116
140
  @scout_scout.stub_get('clients/13431/plugins/12345.xml', 'plugin_data.xml')
117
- @plugin_data = @client.plugin(12345)
141
+ @plugin_data = @server.plugin(12345)
118
142
  end
119
143
  it "should be accessable" do
120
144
  @plugin_data.class.should == ScoutScout::Plugin
@@ -131,5 +155,35 @@ describe "ScoutScout" do
131
155
  end
132
156
 
133
157
  end
158
+ describe 'descriptor list' do
159
+ before(:each) do
160
+ @scout_scout.stub_get('clients/13431.xml', 'client.xml')
161
+ @server = ScoutScout::Server.first(13431)
162
+ @scout_scout.stub_get('descriptors.xml?descriptor=&host=foobar.com&', 'descriptors.xml')
163
+ @descriptors = @server.descriptors
164
+ end
165
+ it "should be accessable" do
166
+ @descriptors.size.should == 30
167
+ end
168
+ it "should be an array ScoutScout::Descriptor objects" do
169
+ @descriptors.first.class.should == ScoutScout::Descriptor
170
+ end
171
+ end
172
+ describe 'descriptor metrics' do
173
+ before(:each) do
174
+ @scout_scout.stub_get('clients/13431.xml', 'client.xml')
175
+ @server = ScoutScout::Server.first(13431)
176
+ @scout_scout.stub_get('clients/13431/plugins.xml', 'plugins.xml')
177
+ @plugins = @server.plugins
178
+ @scout_scout.stub_get('data/value?descriptor=passenger_process_active&function=AVG&consolidate=SUM&host=foobar.com&start=&end=&','data.xml')
179
+ @metric = @plugins.first.descriptors.first.average
180
+ end
181
+ it "should be a ScoutScout::Metric object" do
182
+ @metric.class.should == ScoutScout::Metric
183
+ end
184
+ it "should contain the value" do
185
+ @metric.value.should == '31.10'
186
+ end
187
+ end
134
188
  end
135
189
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scout_scout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Newland
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-31 00:00:00 -05:00
12
+ date: 2010-02-24 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -69,14 +69,18 @@ files:
69
69
  - Rakefile
70
70
  - lib/scout_scout.rb
71
71
  - lib/scout_scout/alert.rb
72
- - lib/scout_scout/client.rb
72
+ - lib/scout_scout/cluster.rb
73
73
  - lib/scout_scout/descriptor.rb
74
+ - lib/scout_scout/metric.rb
74
75
  - lib/scout_scout/plugin.rb
76
+ - lib/scout_scout/server.rb
75
77
  - lib/scout_scout/version.rb
76
78
  - spec/fixtures/activities.xml
77
79
  - spec/fixtures/client.xml
78
80
  - spec/fixtures/client_by_hostname.xml
79
81
  - spec/fixtures/clients.xml
82
+ - spec/fixtures/data.xml
83
+ - spec/fixtures/descriptors.xml
80
84
  - spec/fixtures/plugin_data.xml
81
85
  - spec/fixtures/plugins.xml
82
86
  - spec/scout_scout_spec.rb
@@ -1,53 +0,0 @@
1
- class ScoutScout::Client < Hashie::Mash
2
- def initialize(hash)
3
- if hash['active_alerts']
4
- @alert_hash = hash['active_alerts']
5
- hash.delete('active_alerts')
6
- end
7
- super(hash)
8
- end
9
-
10
- # Search for a client by id or hostname
11
- #
12
- # @return [ScoutScout::Client]
13
- def self.find(client_id_or_hostname)
14
- if client_id_or_hostname.is_a?(Fixnum)
15
- response = ScoutScout.get("/#{ScoutScout.account}/clients/#{client_id_or_hostname}.xml")
16
- ScoutScout::Client.new(response['client'])
17
- else
18
- response = ScoutScout.get("/#{ScoutScout.account}/clients.xml?host=#{client_id_or_hostname}")
19
- ScoutScout::Client.new(response['clients'].first)
20
- end
21
- end
22
-
23
- # Active alerts for this client
24
- #
25
- # @return [Array] An array of ScoutScout::Alert objects
26
- def active_alerts
27
- @active_alerts ||= @alert_hash.map { |a| ScoutScout::Alert.new(a) }
28
- end
29
-
30
- # Recent alerts for this client
31
- #
32
- # @return [Array] An array of ScoutScout::Alert objects
33
- def alerts
34
- response = ScoutScout.get("/#{ScoutScout.account}/clients/#{self.id}/activities.xml")
35
- response['alerts'].map { |alert| ScoutScout::Alert.new(alert) }
36
- end
37
-
38
- # Details about all plugins for this client
39
- #
40
- # @return [Array] An array of ScoutScout::Plugin objects
41
- def plugins
42
- response = ScoutScout.get("/#{ScoutScout.account}/clients/#{self.id}/plugins.xml")
43
- response['plugins'].map { |plugin| ScoutScout::Plugin.new(plugin) }
44
- end
45
-
46
- # Details about a specific plugin
47
- #
48
- # @return [ScoutScout::Plugin]
49
- def plugin(id)
50
- response = ScoutScout.get("/#{ScoutScout.account}/clients/#{self.id}/plugins/#{id}.xml")
51
- ScoutScout::Plugin.new(response['plugin'])
52
- end
53
- end