Class: HipstaScale::NewRelic

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

Constant Summary collapse

BASE_URL =
'https://api.newrelic.com/api/v1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ NewRelic

Returns a new instance of NewRelic.



11
12
13
# File 'lib/hipsta_scale/new_relic.rb', line 11

def initialize(app)
  @app = app
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



9
10
11
# File 'lib/hipsta_scale/new_relic.rb', line 9

def app
  @app
end

Instance Method Details

#busy_percentObject



15
16
17
# File 'lib/hipsta_scale/new_relic.rb', line 15

def busy_percent
  fetch.busy_percent
end

#expire!Object



19
20
21
# File 'lib/hipsta_scale/new_relic.rb', line 19

def expire!
  @_cache = nil
end

#fetchObject



23
24
25
26
27
28
# File 'lib/hipsta_scale/new_relic.rb', line 23

def fetch
  return @_cache unless @_cache.nil?
  json = RestClient.get(url, 'x-api-key' => app.new_relic_key)
  response = JSON.parse(json)
  @_cache = OpenStruct.new(response.first)
end