Class: Carbon::Writer
- Inherits:
-
Object
- Object
- Carbon::Writer
- Defined in:
- lib/carbon/writer.rb
Instance Method Summary collapse
- #add_aggregated_metric(group, name, timestamp, value) ⇒ Object
- #add_metric(group, node, name, timestamp, value) ⇒ Object
- #close_connection ⇒ Object
-
#initialize(host, port, logger) ⇒ Writer
constructor
A new instance of Writer.
- #make_connection ⇒ Object
Constructor Details
#initialize(host, port, logger) ⇒ Writer
Returns a new instance of Writer.
3 4 5 6 7 8 9 |
# File 'lib/carbon/writer.rb', line 3 def initialize(host, port, logger) @host = host @port = port @logger = logger @retries = 0 make_connection() end |
Instance Method Details
#add_aggregated_metric(group, name, timestamp, value) ⇒ Object
29 30 31 32 33 |
# File 'lib/carbon/writer.rb', line 29 def add_aggregated_metric(group, name, , value) command = "us-metrics.#{group}.#{name} #{value} #{}" #@logger.info "EXECUTING CARBON COMMAND: #{command}" @connection.puts command end |
#add_metric(group, node, name, timestamp, value) ⇒ Object
23 24 25 26 27 |
# File 'lib/carbon/writer.rb', line 23 def add_metric(group, node, name, , value) command = "us-metrics.#{group}.#{node}.#{name} #{value} #{}" #@logger.info "EXECUTING CARBON COMMAND: #{command}" @connection.puts command end |
#close_connection ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/carbon/writer.rb', line 15 def close_connection begin @connection.close() rescue SocketError => e puts "Exception closing Carbon connection: #{e.}" end end |
#make_connection ⇒ Object
11 12 13 |
# File 'lib/carbon/writer.rb', line 11 def make_connection @connection = TCPSocket.open(@host, @port) end |