Class: Meter::Backend

Inherits:
Object
  • Object
show all
Defined in:
lib/meter/backend.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#hostObject (readonly)

Returns the value of attribute host.



7
8
9
# File 'lib/meter/backend.rb', line 7

def host
  @host
end

#portObject (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, options = {})
  send_stats stat, value, :g, options
end

#histogram(stat, value, options = {}) ⇒ Object



23
24
25
# File 'lib/meter/backend.rb', line 23

def histogram(stat, value, options = {})
  send_stats stat, value, :h, options
end

#increment(stat, options = {}) ⇒ Object



15
16
17
# File 'lib/meter/backend.rb', line 15

def increment(stat, options = {})
  send_stats stat, 1, :c, options
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