forked from DataDog/dogstatsd-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathudp_connection.rb
More file actions
37 lines (29 loc) · 797 Bytes
/
udp_connection.rb
File metadata and controls
37 lines (29 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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, logger, telemetry)
super(telemetry)
@host = host || ENV.fetch('DD_AGENT_HOST', DEFAULT_HOST)
@port = port || ENV.fetch('DD_DOGSTATSD_PORT', DEFAULT_PORT).to_i
@logger = logger
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