Class: StatsD::Instrument::DogStatsDDatagramBuilder

Inherits:
DatagramBuilder show all
Defined in:
lib/statsd/instrument/dogstatsd_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

Methods inherited from DatagramBuilder

#c, #d, #g, #h, #initialize, #kv, #ms, normalize_string, #normalize_tags, #s, #timing_value_packed, unsupported_datagram_types

Constructor Details

This class inherits a constructor from StatsD::Instrument::DatagramBuilder

Class Method Details

.datagram_classObject



11
12
13
# File 'lib/statsd/instrument/dogstatsd_datagram_builder.rb', line 11

def datagram_class
  StatsD::Instrument::DogStatsDDatagram
end

Instance Method Details

#_e(title, text, timestamp: nil, hostname: nil, aggregation_key: nil, priority: nil, source_type_name: nil, alert_type: nil, tags: nil) ⇒ String

Constructs an event datagram.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/statsd/instrument/dogstatsd_datagram_builder.rb', line 34

def _e(title, text, timestamp: nil, hostname: nil, aggregation_key: nil, priority: nil,
  source_type_name: nil, alert_type: nil, tags: nil)
  escaped_title = "#{@prefix}#{title}".gsub("\n", '\n')
  escaped_text = text.gsub("\n", '\n')

  datagram = +"_e{#{escaped_title.length},#{escaped_text.length}}:#{escaped_title}|#{escaped_text}"
  datagram << "|h:#{hostname}" if hostname
  datagram << "|d:#{timestamp.to_i}" if timestamp
  datagram << "|k:#{aggregation_key}" if aggregation_key
  datagram << "|p:#{priority}" if priority
  datagram << "|s:#{source_type_name}" if source_type_name
  datagram << "|t:#{alert_type}" if alert_type

  unless @default_tags.nil?
    datagram << @default_tags
  end

  unless tags.nil? || tags.empty?
    datagram << (@default_tags.nil? ? "|#" : ",")
    compile_tags(tags, datagram)
  end

  datagram
end

#_sc(name, status, timestamp: nil, hostname: nil, tags: nil, message: nil) ⇒ String

Constructs a service check datagram.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/statsd/instrument/dogstatsd_datagram_builder.rb', line 71

def _sc(name, status, timestamp: nil, hostname: nil, tags: nil, message: nil)
  status_number = status.is_a?(Integer) ? status : SERVICE_CHECK_STATUS_VALUES.fetch(status.to_sym)

  datagram = +"_sc|#{@prefix}#{normalize_name(name)}|#{status_number}"
  datagram << "|h:#{hostname}" if hostname
  datagram << "|d:#{timestamp.to_i}" if timestamp

  unless @default_tags.nil?
    datagram << @default_tags
  end

  unless tags.nil? || tags.empty?
    datagram << (@default_tags.nil? ? "|#" : ",")
    compile_tags(tags, datagram)
  end

  datagram << "|m:#{normalize_name(message)}" if message
  datagram
end

#latency_metric_typeObject



15
16
17
# File 'lib/statsd/instrument/dogstatsd_datagram_builder.rb', line 15

def latency_metric_type
  :d
end