Class: Meter::Backend
- Inherits:
-
Object
- Object
- Meter::Backend
- Defined in:
- lib/meter/backend.rb
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
- #gauge(stat, value, options = {}) ⇒ Object
- #histogram(stat, value, options = {}) ⇒ Object
- #increment(stat, options = {}) ⇒ Object
-
#initialize(host = '127.0.0.1', port = 8125) ⇒ Backend
constructor
A new instance of Backend.
- #log(stat, data = {}) ⇒ Object
Constructor Details
#initialize(host = '127.0.0.1', port = 8125) ⇒ Backend
Returns a new instance of Backend.
9 10 11 12 13 |
# File 'lib/meter/backend.rb', line 9 def initialize(host = '127.0.0.1', port = 8125) @host, @port = host, port @prefix = nil @socket = UDPSocket.new end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
7 8 9 |
# File 'lib/meter/backend.rb', line 7 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
7 8 9 |
# File 'lib/meter/backend.rb', line 7 def port @port end |
Instance Method Details
#gauge(stat, value, options = {}) ⇒ Object
19 20 21 |
# File 'lib/meter/backend.rb', line 19 def gauge(stat, value, = {}) send_stats stat, value, :g, end |
#histogram(stat, value, options = {}) ⇒ Object
23 24 25 |
# File 'lib/meter/backend.rb', line 23 def histogram(stat, value, = {}) send_stats stat, value, :h, end |
#increment(stat, options = {}) ⇒ Object
15 16 17 |
# File 'lib/meter/backend.rb', line 15 def increment(stat, = {}) send_stats stat, 1, :c, end |
#log(stat, data = {}) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/meter/backend.rb', line 27 def log(stat, data = {}) data = { environment: ::Meter.config.environment, Timestamp: Time.now }.merge data data.merge! app: ::Meter.config.namespace, statname: stat ::Meter.config.logger.debug { "Logging #{log_file} - #{data}"} log_file.open('a') { |f| f.puts(JSON.dump data) } end |