Class: Metrics::Reporters::OpenTSDBReporter
- Inherits:
-
Object
- Object
- Metrics::Reporters::OpenTSDBReporter
- Includes:
- Logging
- Defined in:
- lib/ruby-metrics/reporters/opentsdb.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ OpenTSDBReporter
constructor
A new instance of OpenTSDBReporter.
- #report(agent) ⇒ Object
- #send_data(opts = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ OpenTSDBReporter
Returns a new instance of OpenTSDBReporter.
16 17 18 19 20 21 |
# File 'lib/ruby-metrics/reporters/opentsdb.rb', line 16 def initialize( = {}) @hostname = [:hostname] @port = [:port] @client = OpenTSDB::Client.new({:hostname => @hostname, :port => @port}) = [:tags] end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
13 14 15 |
# File 'lib/ruby-metrics/reporters/opentsdb.rb', line 13 def client @client end |
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
11 12 13 |
# File 'lib/ruby-metrics/reporters/opentsdb.rb', line 11 def hostname @hostname end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
12 13 14 |
# File 'lib/ruby-metrics/reporters/opentsdb.rb', line 12 def port @port end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
14 15 16 |
# File 'lib/ruby-metrics/reporters/opentsdb.rb', line 14 def end |
Instance Method Details
#report(agent) ⇒ Object
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 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/ruby-metrics/reporters/opentsdb.rb', line 49 def report(agent) agent.instruments.clone.each do |name, instrument| case instrument when Metrics::Instruments::Counter send_data :name => "#{name}", :value => instrument.to_i, :tags => instrument., :units => instrument.units when Metrics::Instruments::Gauge if instrument.get.is_a? Hash instrument.get.each do |key, value| send_data :name => "#{name}.#{key}", :value => value, :tags => instrument., :units => instrument.units end else send_data :name => "#{name}", :value => instrument.get, :tags => instrument., :units => instrument.units end when Metrics::Instruments::Timer rate_units = "#{instrument.units}/sec" time_units = "sec/#{instrument.units}" send_data :name => "#{name}.count", :value => instrument.count, :tags => instrument., :units => instrument.units [:fifteen_minute_rate, :five_minute_rate, :one_minute_rate].each do |attribute| send_data :name => "#{name}.#{attribute}", :value => instrument.send(attribute), :tags => instrument., :units => rate_units end [:min, :max, :mean].each do |attribute| send_data :name => "#{name}.#{attribute}", :value => instrument.send(attribute), :tags => instrument., :units => time_units end when Metrics::Instruments::Meter send_data :name => "#{name}.count", :value => instrument.counted, :tags => instrument., :units => instrument.units rate_units = "#{instrument.units}/sec" [:fifteen_minute_rate, :five_minute_rate, :one_minute_rate, :mean_rate].each do |attribute| send_data :name => "#{name}.#{attribute}", :value => instrument.send(attribute), :tags => instrument., :units => rate_units end else puts 'Unhandled instrument' end end end |
#send_data(opts = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ruby-metrics/reporters/opentsdb.rb', line 23 def send_data(opts = {}) name = opts[:name] value = opts[:value] units = opts[:units] = opts[:tags] tsdb_data = { :metric => name, :timestamp => Time.now.to_i, :value => value, :tags => } if units tsdb_data[:tags][:units] = units else tsdb_data[:tags][:units] = 'none' end if tsdb_data[:tags].merge!() end @client.put(tsdb_data) end |