Class: Fluent::Plugin::Prometheus::Summary

Inherits:
Metric
  • Object
show all
Defined in:
lib/fluent/plugin/prometheus.rb

Instance Attribute Summary

Attributes inherited from Metric

#desc, #key, #name, #type

Instance Method Summary collapse

Methods inherited from Metric

get, init_label_set, #labels

Constructor Details

#initialize(element, registry, labels) ⇒ Summary

Returns a new instance of Summary.



340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'lib/fluent/plugin/prometheus.rb', line 340

def initialize(element, registry, labels)
  super
  if @key.nil?
    raise ConfigError, "summary metric requires 'key' option"
  end

  begin
    @summary = registry.summary(element['name'].to_sym, docstring: element['desc'], labels: @base_labels.keys)
  rescue ::Prometheus::Client::Registry::AlreadyRegisteredError
    @summary = Fluent::Plugin::Prometheus::Metric.get(registry, element['name'].to_sym, :summary, element['desc'])
  end

  if @initialized
    Fluent::Plugin::Prometheus::Metric.init_label_set(@summary, @base_initlabels, @base_labels)
  end
end

Instance Method Details

#instrument(record, expander) ⇒ Object



357
358
359
360
361
362
363
364
365
366
# File 'lib/fluent/plugin/prometheus.rb', line 357

def instrument(record, expander)
  if @key.is_a?(String)
    value = record[@key]
  else
    value = @key.call(record)
  end
  if value
    @summary.observe(value, labels: labels(record, expander))
  end
end