Sha256: 11edfe8c70e7805a7fbe5897c95e72b183f9f4bc0a61d486cb5896385a5ae461

Contents?: true

Size: 763 Bytes

Versions: 4

Compression:

Stored size: 763 Bytes

Contents

# frozen_string_literal: true

require_relative 'connection'

module Datadog
  class Statsd
    class UDPConnection < Connection
      DEFAULT_HOST = '127.0.0.1'
      DEFAULT_PORT = 8125

      # StatsD host. Defaults to 127.0.0.1.
      attr_reader :host

      # StatsD port. Defaults to 8125.
      attr_reader :port

      def initialize(host, port, **kwargs)
        super(**kwargs)

        @host = host || ENV.fetch('DD_AGENT_HOST', DEFAULT_HOST)
        @port = port || ENV.fetch('DD_DOGSTATSD_PORT', DEFAULT_PORT).to_i
      end

      private

      def connect
        UDPSocket.new.tap do |socket|
          socket.connect(host, port)
        end
      end

      def send_message(message)
        socket.send(message, 0)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dogstatsd-ruby-5.2.0 lib/datadog/statsd/udp_connection.rb
dogstatsd-ruby-5.1.0 lib/datadog/statsd/udp_connection.rb
dogstatsd-ruby-5.0.1 lib/datadog/statsd/udp_connection.rb
dogstatsd-ruby-5.0.0 lib/datadog/statsd/udp_connection.rb