Class: MetriksAddons::SignalFxReporter
- Inherits:
-
BaseReporter
- Object
- BaseReporter
- MetriksAddons::SignalFxReporter
- Defined in:
- lib/metriks-addons/signalfx_reporter.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#source ⇒ Object
Returns the value of attribute source.
-
#tags ⇒ Object
Returns the value of attribute tags.
Instance Method Summary collapse
- #create_datapoints(base_name, metric, time, keys, snapshot_keys = []) ⇒ Object
- #get_datapoints ⇒ Object
-
#initialize(h, token, id, tags, options = {}) ⇒ SignalFxReporter
constructor
A new instance of SignalFxReporter.
- #submit(datapoints) ⇒ Object
Methods inherited from BaseReporter
#flush, #log, #restart, #start, #stop
Constructor Details
#initialize(h, token, id, tags, options = {}) ⇒ SignalFxReporter
Returns a new instance of SignalFxReporter.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/metriks-addons/signalfx_reporter.rb', line 10 def initialize(h, token, id, , = {}) super() @hostname = h @x_sf_token = token @orgid = id = @prefix = [:prefix] @source = [:source] @batch_size = [:batch_size] || 50 if not @logger.nil? RestClient.log = Object.new.tap do |proxy| def proxy.<<() Rails.logger.debug end end end end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
8 9 10 |
# File 'lib/metriks-addons/signalfx_reporter.rb', line 8 def data @data end |
#hostname ⇒ Object
Returns the value of attribute hostname.
8 9 10 |
# File 'lib/metriks-addons/signalfx_reporter.rb', line 8 def hostname @hostname end |
#logger ⇒ Object
Returns the value of attribute logger.
8 9 10 |
# File 'lib/metriks-addons/signalfx_reporter.rb', line 8 def logger @logger end |
#prefix ⇒ Object
Returns the value of attribute prefix.
8 9 10 |
# File 'lib/metriks-addons/signalfx_reporter.rb', line 8 def prefix @prefix end |
#source ⇒ Object
Returns the value of attribute source.
8 9 10 |
# File 'lib/metriks-addons/signalfx_reporter.rb', line 8 def source @source end |
#tags ⇒ Object
Returns the value of attribute tags.
8 9 10 |
# File 'lib/metriks-addons/signalfx_reporter.rb', line 8 def end |
Instance Method Details
#create_datapoints(base_name, metric, time, keys, snapshot_keys = []) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/metriks-addons/signalfx_reporter.rb', line 100 def create_datapoints(base_name, metric, time, keys, snapshot_keys = []) datapoints = [] keys.flatten.each do |key| name = key.to_s.gsub(/^get_/, '') datapoints << { :metric => "#{base_name}.#{name}", :timestamp => time*1000, :value => metric.send(key), :dimensions => } end unless snapshot_keys.empty? snapshot = metric.snapshot snapshot_keys.flatten.each do |key| name = key.to_s.gsub(/^get_/, '') datapoints << { :metric => "#{base_name}.#{name}", :timestamp => time*1000, :value => snapshot.send(key), :dimensions => } end end datapoints end |
#get_datapoints ⇒ Object
44 45 46 47 48 49 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 97 98 |
# File 'lib/metriks-addons/signalfx_reporter.rb', line 44 def get_datapoints time = @time_tracker.now_floored datapoints = {} counter = [] gauge = [] log "debug", "Resgistry: #{@registry}" @registry.each do |name, metric| next if name.nil? || name.empty? name = name.to_s.gsub(/ +/, '_') if @prefix name = "#{@prefix}.#{name}" end case metric when Metriks::Meter counter |= create_datapoints name, metric, time, [ :count, :mean_rate ] when Metriks::Counter counter |= create_datapoints name, metric, time, [ :count ] when Metriks::Gauge gauge |= create_datapoints name, metric, time, [ :value ] when Metriks::UtilizationTimer counter |= create_datapoints name, metric, time, [ :count, :mean_rate, :min, :max, :mean, :stddev, :mean_utilization ], [ :median ] when Metriks::Timer counter |= create_datapoints name, metric, time, [ :count, :mean_rate, :min, :max, :mean, :stddev ], [ :median ] when Metriks::Histogram counter |= create_datapoints name, metric, time, [ :count, :min, :max, :mean, :stddev ], [ :median ] end end datapoints[:counter] = counter if counter.any? datapoints[:gauge] = gauge if gauge.any? datapoints end |
#submit(datapoints) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/metriks-addons/signalfx_reporter.rb', line 32 def submit(datapoints) return if datapoints.empty? jsonstr = datapoints.to_json log "debug", "Json for SignalFx: #{jsonstr}" response = RestClient.post "#{@hostname}?orgid=#{@orgid}", jsonstr, :content_type => :json, :accept => :json, :'X-SF-TOKEN' => @x_sf_token log "info", "Sent #{datapoints.size} metrics to SignalFX" log "debug", "Response is: #{response}" end |