Module: Librato::Metrics::Processor
- Included in:
- Aggregator, Queue
- Defined in:
- lib/librato/metrics/processor.rb
Constant Summary
- MEASUREMENTS_PER_REQUEST =
500
Instance Attribute Summary (collapse)
-
- (Object) last_submit_time
readonly
Returns the value of attribute last_submit_time.
-
- (Object) per_request
readonly
Returns the value of attribute per_request.
-
- (Object) prefix
Returns the value of attribute prefix.
Instance Method Summary (collapse)
-
- (Librato::Metrics::Client) client
The current Client instance this queue is using to authenticate and connect to Librato Metrics.
-
- (Object) persister
The object this MetricSet will use to persist.
-
- (Object) submit
Persist currently queued metrics.
-
- (Object) time(name, options = {})
(also: #benchmark)
Capture execution time for a block and queue it as the value for a metric.
Instance Attribute Details
- (Object) last_submit_time (readonly)
Returns the value of attribute last_submit_time
7 8 9 |
# File 'lib/librato/metrics/processor.rb', line 7 def last_submit_time @last_submit_time end |
- (Object) per_request (readonly)
Returns the value of attribute per_request
7 8 9 |
# File 'lib/librato/metrics/processor.rb', line 7 def per_request @per_request end |
- (Object) prefix
Returns the value of attribute prefix
8 9 10 |
# File 'lib/librato/metrics/processor.rb', line 8 def prefix @prefix end |
Instance Method Details
- (Librato::Metrics::Client) 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.
16 17 18 |
# File 'lib/librato/metrics/processor.rb', line 16 def client @client ||= Librato::Metrics.client end |
- (Object) persister
The object this MetricSet will use to persist
22 23 24 |
# File 'lib/librato/metrics/processor.rb', line 22 def persister @persister ||= create_persister end |
- (Object) submit
Persist currently queued metrics
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/librato/metrics/processor.rb', line 29 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 |
- (Object) time(name, options = {}) 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.
61 62 63 64 65 66 67 68 |
# File 'lib/librato/metrics/processor.rb', line 61 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 |