Class: HerokuVector::Source::NewRelic

Inherits:
Object
  • Object
show all
Defined in:
lib/heroku_vector/source/new_relic.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ NewRelic

Returns a new instance of NewRelic.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/heroku_vector/source/new_relic.rb', line 7

def initialize(options={})
  options[:api_key] ||= HerokuVector.newrelic_api_key
  options[:account_id] ||= HerokuVector.
  options[:app_id] ||= HerokuVector.newrelic_app_id

  @api_key = options[:api_key]
  @account_id = options[:account_id]
  @app_id = options[:app_id]

  NewRelicApi.api_key = api_key
end

Instance Attribute Details

#account_idObject (readonly)

Returns the value of attribute account_id.



5
6
7
# File 'lib/heroku_vector/source/new_relic.rb', line 5

def 
  @account_id
end

#api_keyObject (readonly)

Returns the value of attribute api_key.



5
6
7
# File 'lib/heroku_vector/source/new_relic.rb', line 5

def api_key
  @api_key
end

#app_idObject (readonly)

Returns the value of attribute app_id.



5
6
7
# File 'lib/heroku_vector/source/new_relic.rb', line 5

def app_id
  @app_id
end

Instance Method Details

#newrelic_accountObject



19
20
21
22
# File 'lib/heroku_vector/source/new_relic.rb', line 19

def 
  # Safe to memoize the parent Account
  @newrelic_account ||= NewRelicApi::Account.find( || :first)
end

#newrelic_appObject



24
25
26
27
28
29
30
31
# File 'lib/heroku_vector/source/new_relic.rb', line 24

def newrelic_app
  # App Must be fetched from network every time, to get latest metrics
  if app_id
    .applications.find {|app| app.id == app_id }
  else
    .applications.first
  end
end

#throughputObject Also known as: sample



33
34
35
36
37
38
39
40
41
42
# File 'lib/heroku_vector/source/new_relic.rb', line 33

def throughput
  begin
    # Fetch fresh App instance and extract Trhoughput metric from Threshold Values
    # Threshold Values are current instantaneous measures, not periodic averages
    metric = newrelic_app.threshold_values.find {|m| m.name == 'Throughput' }
    metric.metric_value
  rescue
    return 0.0
  end
end

#unitObject



45
46
47
# File 'lib/heroku_vector/source/new_relic.rb', line 45

def unit
  'RPM'
end