Class: Prometheus::Client::Histogram
- Defined in:
- lib/prometheus/client/histogram.rb
Overview
A histogram samples observations (usually things like request durations or response sizes) and counts them in configurable buckets. It also provides a sum of all observed values.
Defined Under Namespace
Classes: Value
Constant Summary collapse
- DEFAULT_BUCKETS =
DEFAULT_BUCKETS are the default Histogram buckets. The default buckets are tailored to broadly measure the response time (in seconds) of a network service. (From DefBuckets client_golang)
[0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10].freeze
Instance Attribute Summary
Attributes inherited from Metric
#base_labels, #docstring, #name
Instance Method Summary collapse
-
#initialize(name, docstring, base_labels = {}, buckets = DEFAULT_BUCKETS) ⇒ Histogram
constructor
Offer a way to manually specify buckets.
- #observe(labels, value) ⇒ Object
- #type ⇒ Object
Methods inherited from Metric
Methods included from UsesValueType
Constructor Details
#initialize(name, docstring, base_labels = {}, buckets = DEFAULT_BUCKETS) ⇒ Histogram
Offer a way to manually specify buckets
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/prometheus/client/histogram.rb', line 59 def initialize(name, docstring, base_labels = {}, buckets = DEFAULT_BUCKETS) raise ArgumentError, 'Unsorted buckets, typo?' unless sorted? buckets # Precompute both orders once per metric. Shared across all label sets # to avoid per-value allocation and per-observe reverse calls. @buckets = buckets.dup.freeze @buckets_descending = @buckets.reverse.freeze super(name, docstring, base_labels) end |
Instance Method Details
#observe(labels, value) ⇒ Object
75 76 77 78 |
# File 'lib/prometheus/client/histogram.rb', line 75 def observe(labels, value) label_set = label_set_for(labels) synchronize { @values[label_set].observe(value) } end |
#type ⇒ Object
71 72 73 |
# File 'lib/prometheus/client/histogram.rb', line 71 def type :histogram end |