class Fluent::Plugin::Prometheus::Counter
Public Class Methods
Source
# File lib/fluent/plugin/prometheus.rb, line 309 def initialize(element, registry, labels) super begin @counter = registry.counter(element['name'].to_sym, docstring: element['desc'], labels: @base_labels.keys) rescue ::Prometheus::Client::Registry::AlreadyRegisteredError @counter = Fluent::Plugin::Prometheus::Metric.get(registry, element['name'].to_sym, :counter, element['desc']) end if @initialized Fluent::Plugin::Prometheus::Metric.init_label_set(@counter, @base_initlabels, @base_labels) end end
Calls superclass method
Fluent::Plugin::Prometheus::Metric::new
Public Instance Methods
Source
# File lib/fluent/plugin/prometheus.rb, line 322 def instrument(record, expander) # use record value of the key if key is specified, otherwise just increment if @key.nil? value = 1 elsif @key.is_a?(String) value = record[@key] else value = @key.call(record) end # ignore if record value is nil return if value.nil? @counter.increment(by: value, labels: labels(record, expander)) end