Class: Mettric::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/mettric/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = ::Mettric.config) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mettric/client.rb', line 9

def initialize(config = ::Mettric.config)
  @config = config || {}
  @riemann = Riemann::Client.new(
    host:    @config[:host]    || 'localhost',
    port:    @config[:port]    || 5555,
    timeout: @config[:timeout] || 5
  )

  self.app  = (@config[:app] || rails_app_name).to_s.underscore
  self.host = (@config[:reporting_host] || host_name).to_s.underscore
  self.env = (@config[:env] || rails_env).to_s.underscore


  if block_given?
    begin
      yield self
    ensure
      close
    end
  end
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



7
8
9
# File 'lib/mettric/client.rb', line 7

def app
  @app
end

#envObject

Returns the value of attribute env.



7
8
9
# File 'lib/mettric/client.rb', line 7

def env
  @env
end

#hostObject

Returns the value of attribute host.



7
8
9
# File 'lib/mettric/client.rb', line 7

def host
  @host
end

Instance Method Details

#<<(payload) ⇒ Object



45
46
47
48
49
# File 'lib/mettric/client.rb', line 45

def <<(payload)
  @riemann.tcp << standardize_payload(payload)
rescue => e
  track_exception(e, payload)
end

#[](*args) ⇒ Object



51
52
53
# File 'lib/mettric/client.rb', line 51

def [](*args)
  @riemann[*args]
end

#closeObject



55
56
57
# File 'lib/mettric/client.rb', line 55

def close
  @riemann.close
end

#connected?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/mettric/client.rb', line 59

def connected?
  @riemann.connected?
end