Class: Graphite::Client
- Inherits:
-
Object
- Object
- Graphite::Client
- Defined in:
- lib/graphite/client.rb
Instance Method Summary collapse
- #increment!(counter, n = 1) ⇒ Object
-
#initialize(server, prefix, logger = nil) ⇒ Client
constructor
Expects a string in the form of “hostname:port_num” where port_num is optional, and a prefix to identify this server.
- #metric(name, frequency = 1.minute, options = {}) ⇒ Object
- #metrics(frequency = 1.minute) ⇒ Object
- #previous_day_metric(name) ⇒ Object
Constructor Details
#initialize(server, prefix, logger = nil) ⇒ Client
Expects a string in the form of “hostname:port_num” where port_num is optional, and a prefix to identify this server. Example: Graphite::Client.new(“graphite.example.com”, “yourapp.#Rails.env.instances.#hostname.#$$”)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/graphite/client.rb', line 11 def initialize(server, prefix, logger = nil) @logger = Graphite::Logger.new(server,logger) @prefix = prefix @metrics = {} @counters = {} @shifts = {} if block_given? @scheduler = Rufus::Scheduler::EmScheduler.start_new yield self start_logger_timer @scheduler.join else Graphite::EventMachineHandler.ensure_running @scheduler = Rufus::Scheduler::EmScheduler.start_new start_logger_timer end end |
Instance Method Details
#increment!(counter, n = 1) ⇒ Object
56 57 58 59 60 |
# File 'lib/graphite/client.rb', line 56 def increment!(counter, n = 1) full_counter = "#{@prefix}.#{counter}" @counters[full_counter] ||= 0 @counters[full_counter] += n end |
#metric(name, frequency = 1.minute, options = {}) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/graphite/client.rb', line 39 def metric(name, frequency = 1.minute, = {}) add_shifts(name,[:shifts]) if [:shifts] @scheduler.every(frequency, :first_in => '1m') do result = yield log({name => result}) cleanup end end |
#metrics(frequency = 1.minute) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/graphite/client.rb', line 48 def metrics(frequency = 1.minute) @scheduler.every(frequency, :first_in => '1m') do results = yield log(results) cleanup end end |
#previous_day_metric(name) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/graphite/client.rb', line 30 def previous_day_metric(name) @scheduler.every("1d", :first_in => '1m') do date = Date.today - 1 result = yield date log({name + ".daily" => result}) cleanup end end |