Class: StatsdConnector
- Inherits:
-
Object
- Object
- StatsdConnector
- Defined in:
- lib/puma/plugin/statsd.rb
Constant Summary collapse
- ENV_NAME =
"STATSD_HOST"- STATSD_TYPES =
{ count: 'c', gauge: 'g' }
- METRIC_DELIMETER =
".".freeze
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize ⇒ StatsdConnector
constructor
A new instance of StatsdConnector.
- #send(metric_name:, value:, type:, tags: nil) ⇒ Object
Constructor Details
#initialize ⇒ StatsdConnector
Returns a new instance of StatsdConnector.
13 14 15 16 |
# File 'lib/puma/plugin/statsd.rb', line 13 def initialize @host = ENV.fetch(ENV_NAME, "127.0.0.1") @port = ENV.fetch("STATSD_PORT", 8125) end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
11 12 13 |
# File 'lib/puma/plugin/statsd.rb', line 11 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
11 12 13 |
# File 'lib/puma/plugin/statsd.rb', line 11 def port @port end |
Instance Method Details
#send(metric_name:, value:, type:, tags: nil) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/puma/plugin/statsd.rb', line 18 def send(metric_name:, value:, type:, tags: nil) data = "#{metric_name}:#{value}|#{STATSD_TYPES.fetch(type)}" data = "#{data}|##{}" unless .nil? socket = UDPSocket.new socket.send(data, 0, host, port) ensure socket.close end |