Module: StatsD::Instrument::Helpers
- Included in:
- Assertions, Matchers::Matcher
- Defined in:
- lib/statsd/instrument/helpers.rb
Class Method Summary collapse
- .add_tag(tags, key, value) ⇒ Object
- .prefix_metric(metric_name, client: nil) ⇒ Object
- .prefixed_metric?(metric_name, client: nil) ⇒ Boolean
Instance Method Summary collapse
- #capture_statsd_datagrams(client: nil, &block) ⇒ Object (also: #capture_statsd_calls)
Class Method Details
.add_tag(tags, key, value) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/statsd/instrument/helpers.rb', line 15 def add_tag(, key, value) = .dup || {} if .is_a?(String) = .empty? ? "#{key}:#{value}" : "#{},#{key}:#{value}" elsif .is_a?(Array) << "#{key}:#{value}" elsif .is_a?(Hash) [key] = value else raise ArgumentError, "add_tag only supports string, array or hash, #{.class} provided" end end |
.prefix_metric(metric_name, client: nil) ⇒ Object
31 32 33 34 |
# File 'lib/statsd/instrument/helpers.rb', line 31 def prefix_metric(metric_name, client: nil) client ||= StatsD.singleton_client client&.prefix ? "#{client.prefix}.#{metric_name}" : metric_name end |
.prefixed_metric?(metric_name, client: nil) ⇒ Boolean
36 37 38 39 40 41 |
# File 'lib/statsd/instrument/helpers.rb', line 36 def prefixed_metric?(metric_name, client: nil) client ||= StatsD.singleton_client return false unless client&.prefix metric_name =~ /\A#{Regexp.escape(client.prefix)}\./ end |
Instance Method Details
#capture_statsd_datagrams(client: nil, &block) ⇒ Object Also known as: capture_statsd_calls
6 7 8 9 |
# File 'lib/statsd/instrument/helpers.rb', line 6 def capture_statsd_datagrams(client: nil, &block) client ||= StatsD.singleton_client client.capture(&block) end |