class Prometheus::Client::Histogram

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.

Constants

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)

Public Class Methods

new(name, docstring, base_labels = {}, buckets = DEFAULT_BUCKETS) click to toggle source

Offer a way to manually specify buckets

Calls superclass method
# File lib/prometheus/client/histogram.rb, line 40
def initialize(name, docstring, base_labels = {},
               buckets = DEFAULT_BUCKETS)
  raise ArgumentError, 'Unsorted buckets, typo?' unless sorted? buckets

  @buckets = buckets
  super(name, docstring, base_labels)
end

Public Instance Methods

observe(labels, value) click to toggle source
# File lib/prometheus/client/histogram.rb, line 52
def observe(labels, value)
  if labels[:le]
    raise ArgumentError, 'Label with name "le" is not permitted'
  end

  label_set = label_set_for(labels)
  synchronize { @values[label_set].observe(value) }
end
type() click to toggle source
# File lib/prometheus/client/histogram.rb, line 48
def type
  :histogram
end

Private Instance Methods

default() click to toggle source
# File lib/prometheus/client/histogram.rb, line 63
def default
  Value.new(@buckets)
end
sorted?(bucket) click to toggle source
# File lib/prometheus/client/histogram.rb, line 67
def sorted?(bucket)
  bucket.each_cons(2).all? { |i, j| i <= j }
end