Class: StatsD::Instrument::Datagram
- Inherits:
-
Object
- Object
- StatsD::Instrument::Datagram
- Defined in:
- lib/statsd/instrument/datagram.rb
Overview
Note:
This class is part of the new Client implementation that is intended to become the new default in the next major release of this library.
The Datagram class parses and inspects a StatsD datagrams
Direct Known Subclasses
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#initialize(source) ⇒ Datagram
constructor
A new instance of Datagram.
- #inspect ⇒ Object
- #name ⇒ Object
-
#sample_rate ⇒ Float
The sample rate at which this datagram was emitted, between 0 and 1.
- #tags ⇒ Object
- #type ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(source) ⇒ Datagram
Returns a new instance of Datagram.
12 13 14 |
# File 'lib/statsd/instrument/datagram.rb', line 12 def initialize(source) @source = source end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
10 11 12 |
# File 'lib/statsd/instrument/datagram.rb', line 10 def source @source end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/statsd/instrument/datagram.rb', line 54 def eql?(other) case other when StatsD::Instrument::Datagram source == other.source when String source == other else false end end |
#hash ⇒ Object
50 51 52 |
# File 'lib/statsd/instrument/datagram.rb', line 50 def hash source.hash end |
#inspect ⇒ Object
46 47 48 |
# File 'lib/statsd/instrument/datagram.rb', line 46 def inspect "#<#{self.class.name}:\"#{@source}\">" end |
#name ⇒ Object
25 26 27 |
# File 'lib/statsd/instrument/datagram.rb', line 25 def name parsed_datagram[:name] end |
#sample_rate ⇒ Float
Returns The sample rate at which this datagram was emitted, between 0 and 1.
17 18 19 |
# File 'lib/statsd/instrument/datagram.rb', line 17 def sample_rate parsed_datagram[:sample_rate] ? Float(parsed_datagram[:sample_rate]) : 1.0 end |
#tags ⇒ Object
42 43 44 |
# File 'lib/statsd/instrument/datagram.rb', line 42 def @tags ||= parsed_datagram[:tags]&.split(",") end |
#type ⇒ Object
21 22 23 |
# File 'lib/statsd/instrument/datagram.rb', line 21 def type @type ||= parsed_datagram[:type].to_sym end |
#value ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/statsd/instrument/datagram.rb', line 29 def value @value ||= case type when :c Integer(parsed_datagram[:value]) when :g, :h, :d, :kv, :ms Float(parsed_datagram[:value]) when :s String(parsed_datagram[:value]) else parsed_datagram[:value] end end |