Class: Carbon::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/carbon/writer.rb

Instance Method Summary collapse

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, timestamp, value)
	command = "us-metrics.#{group}.#{name} #{value} #{timestamp}"
	#@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, timestamp, value)
	command = "us-metrics.#{group}.#{node}.#{name} #{value} #{timestamp}"
	#@logger.info "EXECUTING CARBON COMMAND: #{command}"
	@connection.puts command
end

#close_connectionObject



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.message}"
	end
end

#make_connectionObject



11
12
13
# File 'lib/carbon/writer.rb', line 11

def make_connection
	@connection = TCPSocket.open(@host, @port)
end