Class: Prometheus::Client::Histogram::Value
- Inherits:
-
Hash
- Object
- Hash
- Prometheus::Client::Histogram::Value
- Includes:
- UsesValueType
- Defined in:
- lib/prometheus/client/histogram.rb
Overview
Value represents the state of a Histogram at a given point.
Instance Attribute Summary collapse
-
#sum ⇒ Object
Returns the value of attribute sum.
-
#total ⇒ Object
Returns the value of attribute total.
-
#total_inf ⇒ Object
Returns the value of attribute total_inf.
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(type, name, labels, buckets, buckets_descending) ⇒ Value
constructor
A new instance of Value.
- #observe(value) ⇒ Object
Methods included from UsesValueType
Constructor Details
#initialize(type, name, labels, buckets, buckets_descending) ⇒ Value
Returns a new instance of Value.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/prometheus/client/histogram.rb', line 15 def initialize(type, name, labels, buckets, buckets_descending) @sum = value_object(type, name, "#{name}_sum", labels) @total = value_object(type, name, "#{name}_count", labels) @total_inf = value_object(type, name, "#{name}_bucket", labels.merge(le: "+Inf")) # Buckets are precomputed/frozen at the metric level; values hold # references to avoid per-label duplication. @buckets, @buckets_descending = buckets, buckets_descending @buckets.each do |bucket| self[bucket] = value_object(type, name, "#{name}_bucket", labels.merge(le: bucket.to_s)) end end |
Instance Attribute Details
#sum ⇒ Object
Returns the value of attribute sum.
13 14 15 |
# File 'lib/prometheus/client/histogram.rb', line 13 def sum @sum end |
#total ⇒ Object
Returns the value of attribute total.
13 14 15 |
# File 'lib/prometheus/client/histogram.rb', line 13 def total @total end |
#total_inf ⇒ Object
Returns the value of attribute total_inf.
13 14 15 |
# File 'lib/prometheus/client/histogram.rb', line 13 def total_inf @total_inf end |
Instance Method Details
#get ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/prometheus/client/histogram.rb', line 43 def get() hash = {} @buckets.each do |bucket| hash[bucket] = self[bucket].get() end hash end |
#observe(value) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/prometheus/client/histogram.rb', line 29 def observe(value) @total_inf.increment() @total.increment() @sum.increment(value) # Write buckets from largest to smallest so any reader always sees # monotonic (cumulative) counts; stop once the observation no longer # fits to skip needless increments. @buckets_descending.each do |bucket| break if value > bucket self[bucket].increment() end end |