Class: Prometheus::Client::Summary
- Defined in:
- lib/prometheus/client/summary.rb
Overview
Summary is an accumulator for samples. It captures Numeric data and provides the total count and sum of observations.
Instance Attribute Summary
Attributes inherited from Metric
#docstring, #name, #preset_labels
Instance Method Summary collapse
-
#get(labels: {}) ⇒ Object
Returns a hash with “sum” and “count” as keys.
- #init_label_set(labels) ⇒ Object
-
#observe(value, labels: {}) ⇒ Object
Records a given value.
- #type ⇒ Object
-
#values ⇒ Object
Returns all label sets with their values expressed as hashes with their sum/count.
Methods inherited from Metric
Constructor Details
This class inherits a constructor from Prometheus::Client::Metric
Instance Method Details
#get(labels: {}) ⇒ Object
Returns a hash with “sum” and “count” as keys
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/prometheus/client/summary.rb', line 25 def get(labels: {}) base_label_set = label_set_for(labels) internal_counters = ["count", "sum"] @store.synchronize do internal_counters.each_with_object({}) do |counter, acc| acc[counter] = @store.get(labels: base_label_set.merge(quantile: counter)) end end end |
#init_label_set(labels) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/prometheus/client/summary.rb', line 48 def init_label_set(labels) base_label_set = label_set_for(labels) @store.synchronize do @store.set(labels: base_label_set.merge(quantile: "count"), val: 0) @store.set(labels: base_label_set.merge(quantile: "sum"), val: 0) end end |
#observe(value, labels: {}) ⇒ Object
Records a given value.
15 16 17 18 19 20 21 22 |
# File 'lib/prometheus/client/summary.rb', line 15 def observe(value, labels: {}) base_label_set = label_set_for(labels) @store.synchronize do @store.increment(labels: base_label_set.merge(quantile: "count"), by: 1) @store.increment(labels: base_label_set.merge(quantile: "sum"), by: value) end end |
#type ⇒ Object
10 11 12 |
# File 'lib/prometheus/client/summary.rb', line 10 def type :summary end |
#values ⇒ Object
Returns all label sets with their values expressed as hashes with their sum/count
38 39 40 41 42 43 44 45 46 |
# File 'lib/prometheus/client/summary.rb', line 38 def values values = @store.all_values values.each_with_object({}) do |(label_set, v), acc| actual_label_set = label_set.reject{|l| l == :quantile } acc[actual_label_set] ||= { "count" => 0.0, "sum" => 0.0 } acc[actual_label_set][label_set[:quantile]] = v end end |