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.
10 11 12 |
# File 'lib/statsd/instrument/datagram.rb', line 10 def initialize(source) @source = source end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
8 9 10 |
# File 'lib/statsd/instrument/datagram.rb', line 8 def source @source end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/statsd/instrument/datagram.rb', line 52 def eql?(other) case other when StatsD::Instrument::Datagram source == other.source when String source == other else false end end |
#hash ⇒ Object
48 49 50 |
# File 'lib/statsd/instrument/datagram.rb', line 48 def hash source.hash end |
#inspect ⇒ Object
44 45 46 |
# File 'lib/statsd/instrument/datagram.rb', line 44 def inspect "#<#{self.class.name}:\"#{@source}\">" end |
#name ⇒ Object
23 24 25 |
# File 'lib/statsd/instrument/datagram.rb', line 23 def name parsed_datagram[:name] end |
#sample_rate ⇒ Float
Returns The sample rate at which this datagram was emitted, between 0 and 1.
15 16 17 |
# File 'lib/statsd/instrument/datagram.rb', line 15 def sample_rate parsed_datagram[:sample_rate] ? Float(parsed_datagram[:sample_rate]) : 1.0 end |
#tags ⇒ Object
40 41 42 |
# File 'lib/statsd/instrument/datagram.rb', line 40 def @tags ||= parsed_datagram[:tags] ? parsed_datagram[:tags].split(',') : nil end |
#type ⇒ Object
19 20 21 |
# File 'lib/statsd/instrument/datagram.rb', line 19 def type @type ||= parsed_datagram[:type].to_sym end |
#value ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/statsd/instrument/datagram.rb', line 27 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 |