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, #s, unsupported_datagram_types

Constructor Details

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

Class Method Details

.datagram_classObject



8
9
10
# File 'lib/statsd/instrument/dogstatsd_datagram_builder.rb', line 8

def self.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

Constricts an event datagram.

Parameters:

  • title (String)

    Event title.

  • text (String)

    Event description. Newlines are allowed.

  • timestamp (Time) (defaults to: nil)

    The of the event. If not provided, Datadog will interpret it as the current timestamp.

  • hostname (String) (defaults to: nil)

    A hostname to associate with the event.

  • aggregation_key (String) (defaults to: nil)

    An aggregation key to group events with the same key.

  • priority (String) (defaults to: nil)

    Priority of the event. Either "normal" (default) or "low".

  • source_type_name (String) (defaults to: nil)

    The source type of the event.

  • alert_type (String) (defaults to: nil)

    Either "error", "warning", "info" (default) or "success".

  • tags (Array, Hash) (defaults to: nil)

    Tags to associate with the event.

Returns:

  • (String)

    The correctly formatted service check datagram

See Also:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/statsd/instrument/dogstatsd_datagram_builder.rb', line 31

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')
  tags = normalize_tags(tags) + default_tags

  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
  datagram << "|##{tags.join(',')}" unless tags.empty?
  datagram
end

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

Constricts a service check datagram.

Parameters:

  • name (String)

    Name of the service

  • status (Symbol)

    Either :ok, :warning, :critical or :unknown

  • timestamp (Time) (defaults to: nil)

    The moment when the service was checked. If not provided, Datadog will interpret it as the current timestamp.

  • hostname (String) (defaults to: nil)

    A hostname to associate with the check.

  • tags (Array, Hash) (defaults to: nil)

    Tags to associate with the check.

  • message (String) (defaults to: nil)

    A message describing the current state of the service check.

Returns:

  • (String)

    The correctly formatted service check datagram

See Also:



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/statsd/instrument/dogstatsd_datagram_builder.rb', line 61

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)
  tags = normalize_tags(tags) + default_tags

  datagram = +"_sc|#{@prefix}#{normalize_name(name)}|#{status_number}"
  datagram << "|h:#{hostname}" if hostname
  datagram << "|d:#{timestamp.to_i}" if timestamp
  datagram << "|##{tags.join(',')}" unless tags.empty?
  datagram << "|m:#{normalize_name(message)}" if message
  datagram
end

#latency_metric_typeObject



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

def latency_metric_type
  :d
end