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
- #enabled? ⇒ Boolean
-
#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.
14 15 16 17 |
# File 'lib/puma/plugin/statsd.rb', line 14 def initialize @host = ENV.fetch(ENV_NAME, nil) @port = ENV.fetch("STATSD_PORT", 8125) end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
12 13 14 |
# File 'lib/puma/plugin/statsd.rb', line 12 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
12 13 14 |
# File 'lib/puma/plugin/statsd.rb', line 12 def port @port end |
Instance Method Details
#enabled? ⇒ Boolean
19 20 21 |
# File 'lib/puma/plugin/statsd.rb', line 19 def enabled? !!host end |
#send(metric_name:, value:, type:, tags: nil) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/puma/plugin/statsd.rb', line 23 def send(metric_name:, value:, type:, tags: nil) data = "#{metric_name}:#{value}|#{STATSD_TYPES.fetch(type)}" data = "#{data}|##{tags}" unless .nil? socket = UDPSocket.new socket.send(data, 0, host, port) ensure socket.close end |