class Hitimes::ValueMetric

A ValueMetric holds the data from measuring a single value over a period of time. In most cases this may be a single measurement at a single point in time.

A good example of a ValueMetric is measuring the number of items in a queue.

A ValueMetric contains a Stats object, therefore ValueMetric has count, max, mean, min, stddev, sum, sumsq methods that delegate to that Stats object for convenience.

Attributes

stats[R]

holds all the statistics

Public Class Methods

new( 'my_metric' ) → ValueMetric click to toggle source
new( 'my_metric', 'foo' => 'bar', 'this' => 42 ) → ValueMetric

Create a new ValueMetric giving it a name and additional data. additional_data may be anything that follows the to_hash protocol.

Calls superclass method Hitimes::Metric::new
# File lib/hitimes/value_metric.rb, line 33
def initialize(name, additional_data = {})
  super(name, additional_data)
  @stats = Stats.new
end

Public Instance Methods

measure( value ) → Float click to toggle source

Give the value as the measurement to the metric. The value is returned

# File lib/hitimes/value_metric.rb, line 44
def measure(value)
  @sampling_start_time ||= utc_microseconds
  @sampling_start_interval ||= Interval.now

  @stats.update(value)

  # update the length of time we have been sampling
  @sampling_delta = @sampling_start_interval.duration_so_far
end
to_hash → Hash click to toggle source

Convert the metric to a hash

Calls superclass method Hitimes::Metric#to_hash
# File lib/hitimes/value_metric.rb, line 60
def to_hash
  result = super
  (Stats::STATS - %w[rate]).each do |stat|
    result[stat] = send(stat)
  end
  result
end