Class: Scout::Plugin

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, ignore = nil) ⇒ Plugin

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



40
41
42
43
44
45
46
47
# File 'lib/scout_api/plugin.rb', line 40

def initialize(hash, ignore = nil) #:nodoc:
  if hash['descriptors'] && hash['descriptors']['descriptor']
    @descriptor_hash = hash['descriptors']['descriptor']
    hash.delete('descriptors')
  end
  @metrics = Scout::MetricProxy.new(self)
  super(hash)
end

Instance Attribute Details

#descriptor_hashObject (readonly)

:nodoc:



37
38
39
# File 'lib/scout_api/plugin.rb', line 37

def descriptor_hash
  @descriptor_hash
end

#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 plugin.
Scout::Plugin.metrics

# Metrics with name =~ 'Memory Used' on this plugin.
Scout::Plugin.metrics.all(:name => 'Memory Used')

# Average value of metrics with name =~ 'Memory Used' on this plugin.
Scout::Plugin.metrics.average(:name => 'Memory Used')

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

# Minumum value...
Scout::Plugin.metrics.minimum(:name => 'Memory Used')

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

# Retrieve data starting @ 5 hours ago ending at 2 hours ago
Scout::Plugin.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::Plugin.metrics.average(:name => 'Memory Used').to_array

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


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

def metrics
  @metrics
end

#serverObject

Returns the value of attribute server.



2
3
4
# File 'lib/scout_api/plugin.rb', line 2

def server
  @server
end

Instance Method Details

#email_subscribersObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/scout_api/plugin.rb', line 49

def email_subscribers
  response = Scout::Account.get("/clients/#{server.id}/email_subscribers?plugin_id=#{id}")
  doc = Nokogiri::HTML(response.body)

  table = doc.css('table.list').first
  user_rows = table.css('tr')[1..-1] # skip first row, which is headings

  user_rows.map do |row|
    name_td, receiving_notifications_td = *row.css('td')

    name = name_td.content.gsub(/[\t\n]/, '')
    checked = receiving_notifications_td.css('input').attribute('checked')
    receiving_notifications = checked && checked.value == 'checked'
    Hashie::Mash.new :name => name, :receiving_notifications => receiving_notifications
  end
end

#triggersObject



66
67
68
69
# File 'lib/scout_api/plugin.rb', line 66

def triggers
  response = Scout::Account.get("/clients/#{server.id}/triggers.xml?plugin_id=#{id}")
  response['triggers'].map { |trigger| decorate_with_server_and_plugin(Scout::Trigger.new(trigger)) }
end