class StatsD::Instrument::DogStatsDDatagramBuilder
@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.
Constants
- SERVICE_CHECK_STATUS_VALUES
Public Class Methods
# File lib/statsd/instrument/dogstatsd_datagram_builder.rb, line 8 def self.datagram_class StatsD::Instrument::DogStatsDDatagram end
Public Instance Methods
Constricts an event datagram.
@param [String] title Event title. @param [String] text Event description. Newlines are allowed. @param [Time] timestamp The of the event. If not provided,
Datadog will interpret it as the current timestamp.
@param [String] hostname A hostname to associate with the event. @param [String] aggregation_key An aggregation key to group events with the same key. @param [String] priority Priority of the event. Either “normal” (default) or “low”. @param [String] source_type_name The source type of the event. @param [String] alert_type Either “error”, “warning”, “info” (default) or “success”. @param [Array, Hash] tags Tags to associate with the event. @return [String] The correctly formatted service check datagram
@see docs.datadoghq.com/developers/dogstatsd/datagram_shell/#events
# 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
Constricts a service check datagram.
@param [String] name Name of the service @param [Symbol] status Either `:ok`, `:warning`, `:critical` or `:unknown` @param [Time] timestamp The moment when the service was checked. If not provided,
Datadog will interpret it as the current timestamp.
@param [String] hostname A hostname to associate with the check. @param [Array, Hash] tags Tags to associate with the check. @param [String] message A message describing the current state of the service check. @return [String] The correctly formatted service check datagram
@see docs.datadoghq.com/developers/dogstatsd/datagram_shell/#service-checks
# 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
# File lib/statsd/instrument/dogstatsd_datagram_builder.rb, line 12 def latency_metric_type :d end