Class: HGAPI::Client
- Inherits:
-
Object
- Object
- HGAPI::Client
- Defined in:
- lib/hg_api/client.rb
Constant Summary collapse
- SUPPORTED_TRANSPORTS =
[:udp, :tcp, :http]
- HTTP_URI =
"https://hostedgraphite.com/api/v1/sink"- HOST =
'carbon.hostedgraphite.com'- PORT =
2003
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #metric(key, value, options = {}) ⇒ Object
- #time(key, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
13 14 15 16 |
# File 'lib/hg_api/client.rb', line 13 def initialize( = {}) @settings = build_settings() @disabled = @settings[:api_key].nil? end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
6 7 8 |
# File 'lib/hg_api/client.rb', line 6 def logger @logger end |
Instance Method Details
#metric(key, value, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/hg_api/client.rb', line 18 def metric(key, value, = {}) return if @disabled begin send_metric(key, value, check_transport!([:via]) || @settings[:default_transport]) rescue SocketError => e logger.error "[HG API] #{e.class} #{e.} while sending metric #{key}" if logger end end |
#time(key, options = {}) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/hg_api/client.rb', line 28 def time(key, = {}) start = Time.now result = yield metric(key, ((Time.now - start) * 1000).round, ) result end |