Class: HerokuVector::Source::NewRelic
- Inherits:
-
Object
- Object
- HerokuVector::Source::NewRelic
- Defined in:
- lib/heroku_vector/source/new_relic.rb
Instance Attribute Summary collapse
-
#account_id ⇒ Object
readonly
Returns the value of attribute account_id.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#app_id ⇒ Object
readonly
Returns the value of attribute app_id.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ NewRelic
constructor
A new instance of NewRelic.
- #newrelic_account ⇒ Object
- #newrelic_app ⇒ Object
- #throughput ⇒ Object (also: #sample)
- #unit ⇒ Object
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(={}) [:api_key] ||= HerokuVector.newrelic_api_key [:account_id] ||= HerokuVector.newrelic_account_id [:app_id] ||= HerokuVector.newrelic_app_id @api_key = [:api_key] @account_id = [:account_id] @app_id = [:app_id] NewRelicApi.api_key = api_key end |
Instance Attribute Details
#account_id ⇒ Object (readonly)
Returns the value of attribute account_id.
5 6 7 |
# File 'lib/heroku_vector/source/new_relic.rb', line 5 def account_id @account_id end |
#api_key ⇒ Object (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_id ⇒ Object (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_account ⇒ Object
19 20 21 22 |
# File 'lib/heroku_vector/source/new_relic.rb', line 19 def newrelic_account # Safe to memoize the parent Account @newrelic_account ||= NewRelicApi::Account.find(account_id || :first) end |
#newrelic_app ⇒ Object
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 newrelic_account.applications.find {|app| app.id == app_id } else newrelic_account.applications.first end end |
#throughput ⇒ Object 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 |
#unit ⇒ Object
45 46 47 |
# File 'lib/heroku_vector/source/new_relic.rb', line 45 def unit 'RPM' end |