class Airbrake::Stat

@since v3.2.0
stat.to_h # Pack and serialize data so it can be transmitted.
stat.increment_ms(2000)
stat = Airbrake::Stat.new
@example
etc.). Incrementing a stat means pushing new performance statistics.
Usually, one Stat corresponds to one metric (route or query,
performance, SQL query performance and such). It’s powered by TDigests.
Stat is a data structure that allows accumulating performance data (route

def increment_ms(ms)

Returns:
  • (void) -

Parameters:
  • ms (Float) --
def increment_ms(ms)
  @mutex.synchronize do
    self.sum += ms
    self.sumsq += ms * ms
    tdigest.push(ms)
  end
end

def initialize(sum: 0.0, sumsq: 0.0, tdigest: TDigest.new(0.05))

Parameters:
  • tdigest (TDigest::TDigest) -- Packed durations. By default,
  • sumsq (Float) -- The squared sum of duration in milliseconds
  • sum (Float) -- The sum of duration in milliseconds
def initialize(sum: 0.0, sumsq: 0.0, tdigest: TDigest.new(0.05))
  @sum = sum
  @sumsq = sumsq
  @tdigest = tdigest
  @mutex = Mutex.new
end

def inspect

Returns:
  • (String) -
def inspect
  "#<struct Airbrake::Stat count=#{tdigest.size}, sum=#{sum}, sumsq=#{sumsq}>"
end

def to_h

Returns:
  • (Hash{String=>Object}) - stats as a hash with compressed TDigest
def to_h
  @mutex.synchronize do
    tdigest.compress!
    {
      'count' => tdigest.size,
      'sum' => sum,
      'sumsq' => sumsq,
      'tdigest' => Base64.strict_encode64(tdigest.as_small_bytes),
    }
  end
end