Module: Librato::Metrics::Processor
- Included in:
- Aggregator, Queue
- Defined in:
- lib/librato/metrics/processor.rb
Overview
Mixin which provides common logic between Queue and Aggregator objects.
Constant Summary collapse
- MEASUREMENTS_PER_REQUEST =
500
Instance Attribute Summary collapse
-
#last_submit_time ⇒ Object
readonly
Returns the value of attribute last_submit_time.
-
#per_request ⇒ Object
readonly
Returns the value of attribute per_request.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
Instance Method Summary collapse
-
#client ⇒ Librato::Metrics::Client
The current Client instance this queue is using to authenticate and connect to Librato Metrics.
-
#persister ⇒ Object
The object this MetricSet will use to persist.
-
#submit ⇒ Object
Persist currently queued metrics.
-
#time(name, options = {}) ⇒ Object
(also: #benchmark)
Capture execution time for a block and queue it as the value for a metric.
Instance Attribute Details
#last_submit_time ⇒ Object (readonly)
Returns the value of attribute last_submit_time.
9 10 11 |
# File 'lib/librato/metrics/processor.rb', line 9 def last_submit_time @last_submit_time end |
#per_request ⇒ Object (readonly)
Returns the value of attribute per_request.
9 10 11 |
# File 'lib/librato/metrics/processor.rb', line 9 def per_request @per_request end |
#prefix ⇒ Object
Returns the value of attribute prefix.
10 11 12 |
# File 'lib/librato/metrics/processor.rb', line 10 def prefix @prefix end |
Instance Method Details
#client ⇒ Librato::Metrics::Client
The current Client instance this queue is using to authenticate and connect to Librato Metrics. This will default to the primary client used by the Librato::Metrics module unless it has been set to something else.
18 19 20 |
# File 'lib/librato/metrics/processor.rb', line 18 def client @client ||= Librato::Metrics.client end |
#persister ⇒ Object
The object this MetricSet will use to persist
24 25 26 |
# File 'lib/librato/metrics/processor.rb', line 24 def persister @persister ||= create_persister end |
#submit ⇒ Object
Persist currently queued metrics
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/librato/metrics/processor.rb', line 31 def submit return true if self.queued.empty? = {:per_request => @per_request} if persister.persist(self.client, self.queued, ) @last_submit_time = Time.now clear and return true end false rescue ClientError # clean up if we hit exceptions if asked to clear if @clear_on_failure raise end |
#time(name, options = {}) ⇒ Object Also known as: benchmark
Capture execution time for a block and queue it as the value for a metric. Times are recorded in milliseconds.
Options are the same as for #add.
63 64 65 66 67 68 69 70 |
# File 'lib/librato/metrics/processor.rb', line 63 def time(name, ={}) start = Time.now yield.tap do duration = (Time.now - start) * 1000.0 # milliseconds metric = {name => .merge({:value => duration})} add metric end end |