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.



10
11
12
# File 'lib/statsd/instrument/datagram.rb', line 10

def initialize(source)
  @source = source
end

Instance Attribute Details

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

Returns:

  • (Boolean)


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

#hashObject



48
49
50
# File 'lib/statsd/instrument/datagram.rb', line 48

def hash
  source.hash
end

#inspectObject



44
45
46
# File 'lib/statsd/instrument/datagram.rb', line 44

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

#nameObject



23
24
25
# File 'lib/statsd/instrument/datagram.rb', line 23

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.



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

#tagsObject



40
41
42
# File 'lib/statsd/instrument/datagram.rb', line 40

def tags
  @tags ||= parsed_datagram[:tags] ? parsed_datagram[:tags].split(',') : nil
end

#typeObject



19
20
21
# File 'lib/statsd/instrument/datagram.rb', line 19

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

#valueObject



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