class Spectator::DistributionSummary
Track the sample distribution of events. An example would be the response sizes for requests hitting an http server.
The class will report measurements for the total amount, the count, max, and the total of the square of the amounts recorded (useful for computing a standard deviation)
Public Class Methods
new(id)
click to toggle source
Initialize a new DistributionSummary
instance with a given id
# File lib/spectator/distribution_summary.rb, line 14 def initialize(id) @id = id @count = AtomicNumber.new(0) @total_amount = AtomicNumber.new(0) @total_sq = AtomicNumber.new(0) @max = AtomicNumber.new(Float::NAN) end
Public Instance Methods
count()
click to toggle source
Get the current amount
# File lib/spectator/distribution_summary.rb, line 33 def count @count.get end
measure()
click to toggle source
Get a list of measurements, and reset the stats The stats returned are the current count, the total amount, the sum of the square of the amounts recorded, and the max value
# File lib/spectator/distribution_summary.rb, line 45 def measure cnt = Measure.new(@id.with_stat('count'), @count.get_and_set(0)) tot = Measure.new(@id.with_stat('totalAmount'), @total_amount.get_and_set(0)) tot_sq = Measure.new(@id.with_stat('totalOfSquares'), @total_sq.get_and_set(0)) mx = Measure.new(@id.with_stat('max'), @max.get_and_set(Float::NAN)) [cnt, tot, tot_sq, mx] end
record(amount)
click to toggle source
Update the statistics kept by the summary with the specified amount.
# File lib/spectator/distribution_summary.rb, line 23 def record(amount) return if amount.negative? @count.add_and_get(1) @total_amount.add_and_get(amount) @total_sq.add_and_get(amount * amount) @max.max(amount) end
total_amount()
click to toggle source
Return the total amount
# File lib/spectator/distribution_summary.rb, line 38 def total_amount @total_amount.get end