class Fluent::Plugin::Prometheus::Histogram
Public Class Methods
new(element, registry, labels)
click to toggle source
Calls superclass method
Fluent::Plugin::Prometheus::Metric::new
# File lib/fluent/plugin/prometheus.rb, line 370 def initialize(element, registry, labels) super if @key.nil? raise ConfigError, "histogram metric requires 'key' option" end begin if element['buckets'] buckets = element['buckets'].split(/,/).map(&:strip).map do |e| e[/\A\d+.\d+\Z/] ? e.to_f : e.to_i end @histogram = registry.histogram(element['name'].to_sym, docstring: element['desc'], labels: @base_labels.keys, buckets: buckets) else @histogram = registry.histogram(element['name'].to_sym, docstring: element['desc'], labels: @base_labels.keys) end rescue ::Prometheus::Client::Registry::AlreadyRegisteredError @histogram = Fluent::Plugin::Prometheus::Metric.get(registry, element['name'].to_sym, :histogram, element['desc']) end if @initialized Fluent::Plugin::Prometheus::Metric.init_label_set(@histogram, @base_initlabels, @base_labels) end end
Public Instance Methods
instrument(record, expander)
click to toggle source
# File lib/fluent/plugin/prometheus.rb, line 394 def instrument(record, expander) if @key.is_a?(String) value = record[@key] else value = @key.call(record) end if value @histogram.observe(value, labels: labels(record, expander)) end end