Class: CarbonClient
- Inherits:
-
Object
- Object
- CarbonClient
- Defined in:
- lib/notify/graphite.rb
Instance Method Summary collapse
- #closeSocket ⇒ Object
- #getSocket ⇒ Object
-
#initialize(hstr) ⇒ CarbonClient
constructor
A new instance of CarbonClient.
- #sendMetric(key, value, time = Time.now) ⇒ Object
Constructor Details
#initialize(hstr) ⇒ CarbonClient
Returns a new instance of CarbonClient.
4 5 6 7 8 |
# File 'lib/notify/graphite.rb', line 4 def initialize(hstr) @host, @port = hstr.split(":") @port = 2003 unless @port @port = @port.to_i end |
Instance Method Details
#closeSocket ⇒ Object
16 17 18 19 |
# File 'lib/notify/graphite.rb', line 16 def closeSocket @socket.close if @socket @socket = nil end |
#getSocket ⇒ Object
10 11 12 13 14 |
# File 'lib/notify/graphite.rb', line 10 def getSocket STDOUT.puts @host @socket = TCPSocket.new(@host.to_s, @port) unless @socket && !@socket.closed? return @socket end |
#sendMetric(key, value, time = Time.now) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/notify/graphite.rb', line 21 def sendMetric(key, value, time = Time.now) begin getSocket.puts("#{key} #{value.to_f} #{time.to_i}") rescue Errno::EPIPE, Errno::EHOSTUNREACH, Errno::EHOSTDOWN @socket = nil return nil end closeSocket if @socket end |