Class: Prometheus::Client::Histogram::Value

Inherits:
Hash
  • Object
show all
Defined in:
lib/prometheus/client/histogram.rb

Overview

Value represents the state of a Histogram at a given point.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buckets) ⇒ Value

Returns a new instance of Value.



15
16
17
18
19
20
21
22
# File 'lib/prometheus/client/histogram.rb', line 15

def initialize(buckets)
  @sum = 0.0
  @total = 0.0

  buckets.each do |bucket|
    self[bucket] = 0.0
  end
end

Instance Attribute Details

#sumObject

Returns the value of attribute sum.



13
14
15
# File 'lib/prometheus/client/histogram.rb', line 13

def sum
  @sum
end

#totalObject

Returns the value of attribute total.



13
14
15
# File 'lib/prometheus/client/histogram.rb', line 13

def total
  @total
end

Instance Method Details

#observe(value) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/prometheus/client/histogram.rb', line 24

def observe(value)
  @sum += value
  @total += 1

  each_key do |bucket|
    self[bucket] += 1 if value <= bucket
  end
end