Class: Metriks::Reporter::Riemann
- Inherits:
-
Object
- Object
- Metriks::Reporter::Riemann
- Defined in:
- lib/metriks/reporter/riemann.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
- #flush ⇒ Object
-
#initialize(options = {}) ⇒ Riemann
constructor
A new instance of Riemann.
- #restart ⇒ Object
- #send_metric(name, type, metric, keys, snapshot_keys = []) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Riemann
Returns a new instance of Riemann.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/metriks/reporter/riemann.rb', line 6 def initialize( = {}) @client = ::Riemann::Client.new( :host => [:host], :port => [:port] ) @registry = [:registry] || Metriks::Registry.default @interval = [:interval] || 60 @on_error = [:on_error] || proc { |ex| } @default_event = [:default_event] || {} @default_event[:ttl] ||= @interval * 1.5 end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
5 6 7 |
# File 'lib/metriks/reporter/riemann.rb', line 5 def client @client end |
Instance Method Details
#flush ⇒ Object
45 46 47 48 49 50 |
# File 'lib/metriks/reporter/riemann.rb', line 45 def flush # Is this supposed to take interval into account? --aphyr if !@last_write || @last_write.min != Time.now.min write end end |
#restart ⇒ Object
40 41 42 43 |
# File 'lib/metriks/reporter/riemann.rb', line 40 def restart stop start end |
#send_metric(name, type, metric, keys, snapshot_keys = []) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/metriks/reporter/riemann.rb', line 98 def send_metric(name, type, metric, keys, snapshot_keys = []) keys.each do |key| @client << @default_event.merge( :service => "#{name} #{key}", :metric => metric.send(key), :tags => [type] ) end unless snapshot_keys.empty? snapshot = metric.snapshot snapshot_keys.each do |key| @client << @default_event.merge( :service => "#{name} #{key}", :metric => snapshot.send(key), :tags => [type] ) end end end |
#start ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/metriks/reporter/riemann.rb', line 19 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
35 36 37 38 |
# File 'lib/metriks/reporter/riemann.rb', line 35 def stop @thread.kill if @thread @thread = nil end |
#write ⇒ Object
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/riemann.rb', line 52 def write @last_write = Time.now @registry.each do |name, metric| case metric when Metriks::Meter send_metric name, 'meter', metric, [ :count, :one_minute_rate, :five_minute_rate, :fifteen_minute_rate, :mean_rate ] when Metriks::Counter send_metric name, 'counter', metric, [ :count ] when Metriks::Gauge send_metric name, 'gauge', metric, [ :value ] when Metriks::UtilizationTimer send_metric name, 'utilization_timer', 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, 'timer', 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, 'histogram', metric, [ :count, :min, :max, :mean, :stddev ], [ :median, :get_95th_percentile ] end end end |