Class: Metriks::Reporter::Opentsdb
- Inherits:
-
Object
- Object
- Metriks::Reporter::Opentsdb
- Defined in:
- lib/metriks/reporter/opentsdb.rb
Instance Attribute Summary collapse
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #close_connection ⇒ Object
- #connection ⇒ Object
-
#initialize(host, port, options = {}) ⇒ Opentsdb
constructor
A new instance of Opentsdb.
- #open_connection ⇒ Object
- #restart ⇒ Object
- #send_metric(compound_name, metric, keys, snapshot_keys = []) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(host, port, options = {}) ⇒ Opentsdb
Returns a new instance of Opentsdb.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/metriks/reporter/opentsdb.rb', line 9 def initialize(host, port, = {}) @host = host @port = port @prefix = [:prefix] @source = [:source] @interval = [:interval] || 60 @registry = [:registry] || Metriks::Registry.default @on_error = [:on_error] || proc { |ex| } end |
Instance Attribute Details
#prefix ⇒ Object
Returns the value of attribute prefix.
7 8 9 |
# File 'lib/metriks/reporter/opentsdb.rb', line 7 def prefix @prefix end |
#source ⇒ Object
Returns the value of attribute source.
7 8 9 |
# File 'lib/metriks/reporter/opentsdb.rb', line 7 def source @source end |
Instance Method Details
#close_connection ⇒ Object
97 98 99 100 101 102 |
# File 'lib/metriks/reporter/opentsdb.rb', line 97 def close_connection if connection.ready? raise "Error while pushing data: #{connection.gets}" end connection.close end |
#connection ⇒ Object
22 23 24 |
# File 'lib/metriks/reporter/opentsdb.rb', line 22 def connection @connection end |
#open_connection ⇒ Object
19 20 21 |
# File 'lib/metriks/reporter/opentsdb.rb', line 19 def open_connection @connection = TCPSocket.new(@host, @port) end |
#restart ⇒ Object
45 46 47 48 |
# File 'lib/metriks/reporter/opentsdb.rb', line 45 def restart stop start end |
#send_metric(compound_name, metric, keys, snapshot_keys = []) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/metriks/reporter/opentsdb.rb', line 103 def send_metric(compound_name, metric, keys, snapshot_keys = []) name, = compound_name.split("#") if keys.size == 1 # puts "put #{name} #{Time.now.to_i} #{metric.send(keys.first)} #{tags}" connection.puts("put #{name} #{Time.now.to_i} #{metric.send(keys.first)} #{}") else keys.each do |key| #puts "put #{name}.#{key} #{Time.now.to_i} #{metric.send(key)} #{tags}" connection.puts("put #{name}.#{key} #{Time.now.to_i} #{metric.send(key)} #{}") end end end |
#start ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/metriks/reporter/opentsdb.rb', line 25 def start @thread ||= Thread.new do loop do sleep @interval Thread.new do begin write rescue Exception => ex @on_error[ex] rescue nil end end end end end |
#stop ⇒ Object
40 41 42 43 |
# File 'lib/metriks/reporter/opentsdb.rb', line 40 def stop @thread.kill if @thread @thread = nil end |
#write ⇒ Object
50 51 52 53 54 55 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 |
# File 'lib/metriks/reporter/opentsdb.rb', line 50 def write open_connection @registry.each do |name, metric| case metric when Metriks::Meter send_metric name, metric, [ :count, :one_minute_rate, :five_minute_rate, :fifteen_minute_rate, :mean_rate ] when Metriks::Counter send_metric name, metric, [ :count ] metric.clear if metric.reset_on_submit when Metriks::Gauge send_metric name, metric, [ :value ] when Metriks::UtilizationTimer send_metric name, metric, [ :count, :one_minute_rate, :five_minute_rate, :fifteen_minute_rate, :mean_rate, :min, :max, :mean, :stddev, :one_minute_utilization, :five_minute_utilization, :fifteen_minute_utilization, :mean_utilization, ], [ :median, :get_95th_percentile ] when Metriks::Timer send_metric name, metric, [ :count, :one_minute_rate, :five_minute_rate, :fifteen_minute_rate, :mean_rate, :min, :max, :mean, :stddev ], [ :median, :get_95th_percentile ] when Metriks::Histogram send_metric name, metric, [ :count, :min, :max, :mean, :stddev ], [ :median, :get_95th_percentile ] end end close_connection end |