Class: ActiveMeasure::Client
- Inherits:
-
Object
- Object
- ActiveMeasure::Client
- Extended by:
- Forwardable
- Defined in:
- lib/active_measure/client.rb
Constant Summary collapse
- DEFAULT_CONNECTION_STRING =
'udp://localhost:8125'
- METRIC_METHODS =
forward all methods to transport
%i( increment decrement count gauge timing time histogram set distribution ).freeze
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#transport ⇒ Object
readonly
Returns the value of attribute transport.
Instance Method Summary collapse
- #filter_tags(tags) ⇒ Object
-
#initialize(connection_string = nil, logger: nil, tags: {}, namespace: nil) ⇒ Client
constructor
A new instance of Client.
- #parse_connection_string(connection) ⇒ Object
Constructor Details
#initialize(connection_string = nil, logger: nil, tags: {}, namespace: nil) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 |
# File 'lib/active_measure/client.rb', line 13 def initialize(connection_string = nil, logger: nil, tags: {}, namespace: nil) @connection_string = parse_connection_string(connection_string) @connection_string[:client] = self @transport = ActiveMeasure::Adapters.for(@connection_string[:adapter]).new(@connection_string) @logger = logger || ActiveMeasure.logger @tags = () end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
10 11 12 |
# File 'lib/active_measure/client.rb', line 10 def logger @logger end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
11 12 13 |
# File 'lib/active_measure/client.rb', line 11 def namespace @namespace end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
10 11 12 |
# File 'lib/active_measure/client.rb', line 10 def @tags end |
#transport ⇒ Object (readonly)
Returns the value of attribute transport.
11 12 13 |
# File 'lib/active_measure/client.rb', line 11 def transport @transport end |
Instance Method Details
#filter_tags(tags) ⇒ Object
63 64 65 |
# File 'lib/active_measure/client.rb', line 63 def () (ActiveMeasure. || {}).merge( || {}).reject { |_, value| value.nil? || value.empty? } end |
#parse_connection_string(connection) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/active_measure/client.rb', line 38 def parse_connection_string(connection) connection ||= ENV['ActiveMeasure_URL'] default_connection = { scheme: 'statsd', host: 'localhost', port: 8125, adapter: 'statsd' } return default_connection if connection.nil? if connection.is_a?(Hash) connection[:port] ||= default_connection[:port] connection else uri = URI.parse(connection) { scheme: uri.scheme, host: uri.host, port: uri.port || default_connection[:port], adapter: determine_adapter(uri.scheme) } end end |