Class: Minitest::Queue::Statsd
- Inherits:
-
Object
- Object
- Minitest::Queue::Statsd
- Defined in:
- lib/minitest/queue/statsd.rb
Instance Attribute Summary collapse
-
#addr ⇒ Object
readonly
Returns the value of attribute addr.
-
#default_tags ⇒ Object
readonly
Returns the value of attribute default_tags.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Class Method Summary collapse
Instance Method Summary collapse
- #increment(metric, tags: [], value: 1) ⇒ Object
-
#initialize(addr: nil, default_tags: [], namespace: nil) ⇒ Statsd
constructor
A new instance of Statsd.
- #measure(metric, duration = nil, tags: [], &block) ⇒ Object
Constructor Details
#initialize(addr: nil, default_tags: [], namespace: nil) ⇒ Statsd
Returns a new instance of Statsd.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/minitest/queue/statsd.rb', line 12 def initialize(addr: nil, default_tags: [], namespace: nil) @default_tags = @namespace = namespace @addr = addr if addr host, port = addr.split(':', 2) @socket = UDPSocket.new @socket.connect(host, Integer(port)) end rescue SocketError # No-op, we shouldn't fail CI because of statsd end |
Instance Attribute Details
#addr ⇒ Object (readonly)
Returns the value of attribute addr.
10 11 12 |
# File 'lib/minitest/queue/statsd.rb', line 10 def addr @addr end |
#default_tags ⇒ Object (readonly)
Returns the value of attribute default_tags.
10 11 12 |
# File 'lib/minitest/queue/statsd.rb', line 10 def @default_tags end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
10 11 12 |
# File 'lib/minitest/queue/statsd.rb', line 10 def namespace @namespace end |
Class Method Details
.measure_duration ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/minitest/queue/statsd.rb', line 40 def self.measure_duration before = Process.clock_gettime(Process::CLOCK_REALTIME, :millisecond) return_value = yield after = Process.clock_gettime(Process::CLOCK_REALTIME, :millisecond) [return_value, after - before] end |
Instance Method Details
#increment(metric, tags: [], value: 1) ⇒ Object
26 27 28 |
# File 'lib/minitest/queue/statsd.rb', line 26 def increment(metric, tags: [], value: 1) send_metric(type: 'c', value: value, metric: metric, tags: + ) end |
#measure(metric, duration = nil, tags: [], &block) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/minitest/queue/statsd.rb', line 30 def measure(metric, duration = nil, tags: [], &block) if block_given? return_value, duration = Minitest::Queue::Statsd.measure_duration(&block) elsif duration.nil? raise ArgumentError, "You need to pass a block or pass a float as second argument." end send_metric(type: 'ms', value: duration, metric: metric, tags: + ) return_value end |