Class: StatsD::Instrument::DatagramBuilder

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/statsd/instrument/datagram_builder.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.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix: nil, default_tags: nil) ⇒ DatagramBuilder

Returns a new instance of DatagramBuilder.



28
29
30
31
# File 'lib/statsd/instrument/datagram_builder.rb', line 28

def initialize(prefix: nil, default_tags: nil)
  @prefix = prefix.nil? ? "" : "#{prefix}.".tr(":|@", "_")
  @default_tags = default_tags.nil? || default_tags.empty? ? nil : compile_tags(default_tags, "|#".b)
end

Class Method Details

.datagram_classObject



18
19
20
# File 'lib/statsd/instrument/datagram_builder.rb', line 18

def datagram_class
  StatsD::Instrument::Datagram
end

.normalize_string(string) ⇒ Object



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

def normalize_string(string)
  string = string.tr("|#", "_") if /[|#]/.match?(string)
  string
end

.unsupported_datagram_types(*types) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/statsd/instrument/datagram_builder.rb', line 10

def unsupported_datagram_types(*types)
  types.each do |type|
    define_method(type) do |_, _, _, _|
      raise NotImplementedError, "Type #{type} metrics are not supported by #{self.class.name}."
    end
  end
end

Instance Method Details

#c(name, value, sample_rate, tags) ⇒ Object



33
34
35
# File 'lib/statsd/instrument/datagram_builder.rb', line 33

def c(name, value, sample_rate, tags)
  generate_generic_datagram(name, value, "c", sample_rate, tags)
end

#d(name, value, sample_rate, tags) ⇒ Object



53
54
55
# File 'lib/statsd/instrument/datagram_builder.rb', line 53

def d(name, value, sample_rate, tags)
  generate_generic_datagram(name, value, "d", sample_rate, tags)
end

#g(name, value, sample_rate, tags) ⇒ Object



37
38
39
# File 'lib/statsd/instrument/datagram_builder.rb', line 37

def g(name, value, sample_rate, tags)
  generate_generic_datagram(name, value, "g", sample_rate, tags)
end

#h(name, value, sample_rate, tags) ⇒ Object



49
50
51
# File 'lib/statsd/instrument/datagram_builder.rb', line 49

def h(name, value, sample_rate, tags)
  generate_generic_datagram(name, value, "h", sample_rate, tags)
end

#kv(name, value, sample_rate, tags) ⇒ Object



63
64
65
# File 'lib/statsd/instrument/datagram_builder.rb', line 63

def kv(name, value, sample_rate, tags)
  generate_generic_datagram(name, value, "kv", sample_rate, tags)
end

#latency_metric_typeObject



67
68
69
# File 'lib/statsd/instrument/datagram_builder.rb', line 67

def latency_metric_type
  :ms
end

#ms(name, value, sample_rate, tags) ⇒ Object



41
42
43
# File 'lib/statsd/instrument/datagram_builder.rb', line 41

def ms(name, value, sample_rate, tags)
  generate_generic_datagram(name, value, "ms", sample_rate, tags)
end

#normalize_tags(tags, buffer = "".b) ⇒ Object



71
72
73
# File 'lib/statsd/instrument/datagram_builder.rb', line 71

def normalize_tags(tags, buffer = "".b)
  compile_tags(tags, buffer)
end

#s(name, value, sample_rate, tags) ⇒ Object



45
46
47
# File 'lib/statsd/instrument/datagram_builder.rb', line 45

def s(name, value, sample_rate, tags)
  generate_generic_datagram(name, value, "s", sample_rate, tags)
end

#timing_value_packed(name, type, values, sample_rate, tags) ⇒ Object



57
58
59
60
61
# File 'lib/statsd/instrument/datagram_builder.rb', line 57

def timing_value_packed(name, type, values, sample_rate, tags)
  # here values is an array
  values = values.join(":")
  generate_generic_datagram(name, values, type, sample_rate, tags)
end