Class: GraphiteAPI::Client
- Inherits:
-
Object
- Object
- GraphiteAPI::Client
- Extended by:
- Forwardable
- Defined in:
- lib/graphite-api/client.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#check! ⇒ Object
throw exception on Socket error.
- #every(interval, &block) ⇒ Object
- #increment(*keys) ⇒ Object
-
#initialize(opt) ⇒ Client
constructor
A new instance of Client.
- #join ⇒ Object
- #metrics(metric, time = nil, aggregation_method = nil) ⇒ Object
- #timers ⇒ Object
Constructor Details
#initialize(opt) ⇒ Client
Returns a new instance of Client.
18 19 20 21 22 23 24 25 |
# File 'lib/graphite-api/client.rb', line 18 def initialize opt @options = validate opt.clone @buffer = GraphiteAPI::Buffer.new , timers @connectors = GraphiteAPI::Connector::Group.new @mu = Mutex.new timers.every([:interval], true, &method(:send_metrics!)) unless [:direct] end |
Class Method Details
.default_options ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/graphite-api/client.rb', line 59 def self. { :backends => [], :cleaner_interval => 43200, :port => 2003, :log_level => :info, :cache => nil, :host => "localhost", :prefix => [], :interval => 0, :slice => 60, :pid => "/tmp/graphite-middleware.pid", :default_aggregation_method => :sum } end |
Instance Method Details
#check! ⇒ Object
throw exception on Socket error
32 33 34 |
# File 'lib/graphite-api/client.rb', line 32 def check! connectors.check! end |
#every(interval, &block) ⇒ Object
36 37 38 |
# File 'lib/graphite-api/client.rb', line 36 def every interval, &block @timers.every(interval) { block.arity == 1 ? block.call(self) : block.call } end |
#increment(*keys) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/graphite-api/client.rb', line 46 def increment(*keys) opt = {} opt.merge! keys.pop if keys.last.is_a? Hash by = opt.fetch(:by,1) time = opt.fetch(:time,Time.now) metric = keys.inject({}) {|h,k| h.merge k => by } metrics(metric, time) end |
#join ⇒ Object
55 56 57 |
# File 'lib/graphite-api/client.rb', line 55 def join sleep while buffer.new_records? end |
#metrics(metric, time = nil, aggregation_method = nil) ⇒ Object
40 41 42 43 44 |
# File 'lib/graphite-api/client.rb', line 40 def metrics metric, time = nil, aggregation_method = nil return if metric.empty? buffer.push :metric => metric, :time => (time || Time.now), :aggregation_method => aggregation_method send_metrics! if [:direct] end |
#timers ⇒ Object
27 28 29 |
# File 'lib/graphite-api/client.rb', line 27 def timers @timers ||= Timers::Group.new.tap {|t| Thread.new { loop { t.wait } } } end |