Class: LogStash::Outputs::Opentsdb
- Defined in:
- lib/logstash/outputs/opentsdb.rb
Overview
This output allows you to pull metrics from your logs and ship them to opentsdb. Opentsdb is an open source tool for storing and graphing metrics.
Constant Summary
Constants included from Config::Mixin
Instance Attribute Summary
Attributes included from Config::Mixin
Attributes inherited from Plugin
Instance Method Summary collapse
-
#connect ⇒ Object
def register.
- #receive(event) ⇒ Object
- #register ⇒ Object
Methods inherited from Base
#handle, #handle_worker, #initialize, #worker_setup, #workers_not_supported
Methods included from Config::Mixin
Methods inherited from Plugin
#eql?, #finished, #finished?, #hash, #initialize, #inspect, lookup, #reload, #running?, #shutdown, #teardown, #terminating?, #to_s
Constructor Details
This class inherits a constructor from LogStash::Outputs::Base
Instance Method Details
#connect ⇒ Object
def register
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/logstash/outputs/opentsdb.rb', line 43 def connect # TODO(sissel): Test error cases. Catch exceptions. Find fortune and glory. begin @socket = TCPSocket.new(@host, @port) rescue Errno::ECONNREFUSED => e @logger.warn("Connection refused to opentsdb server, sleeping...", :host => @host, :port => @port) sleep(2) retry end end |
#receive(event) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/logstash/outputs/opentsdb.rb', line 56 def receive(event) return unless output?(event) # Opentsdb message format: put metric timestamp value tagname=tagvalue tag2=value2\n # Catch exceptions like ECONNRESET and friends, reconnect on failure. begin name = metrics[0] value = metrics[1] = metrics[2..-1] # The first part of the message = ['put', event.sprintf(name), event.sprintf("%{+%s}"), event.sprintf(value), ].join(" ") # If we have have tags we need to add it to the message = [] unless .nil? Hash[*.flatten].each do |tag_name,tag_value| # Interprete variables if neccesary real_tag_name = event.sprintf(tag_name) real_tag_value = event.sprintf(tag_value) << [real_tag_name , real_tag_value ].join('=') end +=' '+.join(' ') end # TODO(sissel): Test error cases. Catch exceptions. Find fortune and glory. begin @socket.puts() rescue Errno::EPIPE, Errno::ECONNRESET => e @logger.warn("Connection to opentsdb server died", :exception => e, :host => @host, :port => @port) sleep(2) connect end # TODO(sissel): resend on failure # TODO(sissel): Make 'resend on failure' tunable; sometimes it's OK to # drop metrics. end # @metrics.each end |
#register ⇒ Object
39 40 41 |
# File 'lib/logstash/outputs/opentsdb.rb', line 39 def register connect end |