Class: Librato::LogReporter
- Inherits:
-
Object
- Object
- Librato::LogReporter
- Includes:
- Configuration
- Defined in:
- lib/librato/logreporter.rb,
lib/librato/logreporter/group.rb,
lib/librato/logreporter/version.rb,
lib/librato/logreporter/configuration.rb
Overview
Provides a common interface to reporting metrics with methods like #increment, #measure, #timing, #group - all written to your preferred IO stream.
Defined Under Namespace
Modules: Configuration Classes: Group
Constant Summary collapse
- VERSION =
'0.2.1'
Instance Method Summary collapse
-
#group(prefix) {|Group.new(collector: self, prefix: prefix)| ... } ⇒ Object
Group a set of metrics by common prefix.
-
#increment(counter, options = {}) ⇒ Object
Increment a given metric.
- #measure(*args, &block) ⇒ Object (also: #timing)
Methods included from Configuration
#log, #log=, #prefix, #prefix=, #source, #source=
Instance Method Details
#group(prefix) {|Group.new(collector: self, prefix: prefix)| ... } ⇒ Object
Group a set of metrics by common prefix
30 31 32 |
# File 'lib/librato/logreporter.rb', line 30 def group(prefix) yield Group.new(collector: self, prefix: prefix) end |
#increment(counter, options = {}) ⇒ Object
Increment a given metric
45 46 47 48 |
# File 'lib/librato/logreporter.rb', line 45 def increment(counter, ={}) by = [:by] || 1 log_write(counter => by, :l2met_type => 'count', :source => [:source]) end |
#measure(*args, &block) ⇒ Object Also known as: timing
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/librato/logreporter.rb', line 64 def measure(*args, &block) = {} event = args[0].to_s returned = nil # handle block or specified argument if block_given? start = Time.now returned = yield value = ((Time.now - start) * 1000.0).to_i elsif args[1] value = args[1] else raise "no value provided" end # detect options hash if present if args.length > 1 and args[-1].respond_to?(:each) = args[-1] end log_write(event => value, :source => [:source]) returned end |