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(name, value, units = nil) ⇒ 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] || {:units => 'none'} 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
38 39 40 41 42 43 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 |
# File 'lib/ruby-metrics/reporters/opentsdb.rb', line 38 def report(agent) agent.instruments.clone.each do |name, instrument| case instrument when Metrics::Instruments::Counter value = instrument.to_i send_data name, value when Metrics::Instruments::Gauge if instrument.get.is_a? Hash instrument.get.each do |key, value| send_data "#{name}.#{key}", value end else send_data name, instrument.get, instrument.units end when Metrics::Instruments::Timer rate_units = "#{instrument.units}/sec" time_units = "sec/#{instrument.units}" send_data "#{name}.count", instrument.count, instrument.units [:fifteen_minute_rate, :five_minute_rate, :one_minute_rate].each do |attribute| send_data "#{name}.#{attribute}", instrument.send(attribute), rate_units end [:min, :max, :mean].each do |attribute| send_data "#{name}.#{attribute}", instrument.send(attribute), time_units end when Metrics::Instruments::Meter rate_units = "#{instrument.units}/sec" send_data "#{name}.count", instrument.count, instrument.units [:fifteen_minute_rate, :five_minute_rate, :one_minute_rate, :mean_rate].each do |attribute| send_data "#{name}.#{attribute}", instrument.send(attribute), rate_units end else puts 'Unhandled instrument' end end end |
#send_data(name, value, units = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ruby-metrics/reporters/opentsdb.rb', line 23 def send_data(name, value, units = nil) tsdb_data = { :metric => name, :timestamp => Time.now.to_i, :value => value, :tags => } if units tsdb_data[:tags][:units] = units end @client.put(tsdb_data) end |