Class: StatsD::Instrument::Datagram

Inherits:
Object
  • Object
show all
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

DogStatsDDatagram

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#sourceObject (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: ==

Returns:

  • (Boolean)


58
59
60
61
62
63
64
65
66
67
# File 'lib/statsd/instrument/datagram.rb', line 58

def eql?(other)
  case other
  when StatsD::Instrument::Datagram
    source == other.source
  when String
    source == other
  else
    false
  end
end

#hashObject



54
55
56
# File 'lib/statsd/instrument/datagram.rb', line 54

def hash
  source.hash
end

#inspectObject



50
51
52
# File 'lib/statsd/instrument/datagram.rb', line 50

def inspect
  "#<#{self.class.name}:\"#{@source}\">"
end

#nameObject



25
26
27
# File 'lib/statsd/instrument/datagram.rb', line 25

def name
  parsed_datagram[:name]
end

#sample_rateFloat

Returns The sample rate at which this datagram was emitted, between 0 and 1.

Returns:

  • (Float)

    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

#tagsObject



46
47
48
# File 'lib/statsd/instrument/datagram.rb', line 46

def tags
  @tags ||= parsed_datagram[:tags]&.split(",")
end

#typeObject



21
22
23
# File 'lib/statsd/instrument/datagram.rb', line 21

def type
  @type ||= parsed_datagram[:type].to_sym
end

#valueObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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
    if parsed_datagram[:value].include?(":")
      parsed_datagram[:value].split(":").map { |v| Float(v) }
    else
      Float(parsed_datagram[:value])
    end
  when :s
    String(parsed_datagram[:value])
  else
    parsed_datagram[:value]
  end
end