Class: Fluent::Prometheus::Counter
- Defined in:
- lib/fluent/plugin/prometheus.rb
Instance Attribute Summary
Attributes inherited from Metric
Instance Method Summary collapse
-
#initialize(element, registry, labels) ⇒ Counter
constructor
A new instance of Counter.
- #instrument(record, expander) ⇒ Object
Methods inherited from Metric
Constructor Details
#initialize(element, registry, labels) ⇒ Counter
Returns a new instance of Counter.
154 155 156 157 158 159 160 161 |
# File 'lib/fluent/plugin/prometheus.rb', line 154 def initialize(element, registry, labels) super begin @counter = registry.counter(element['name'].to_sym, element['desc']) rescue ::Prometheus::Client::Registry::AlreadyRegisteredError @counter = Fluent::Prometheus::Metric.get(registry, element['name'].to_sym, :counter, element['desc']) end end |
Instance Method Details
#instrument(record, expander) ⇒ Object
163 164 165 166 167 168 169 170 171 |
# File 'lib/fluent/plugin/prometheus.rb', line 163 def instrument(record, ) # use record value of the key if key is specified, otherwise just increment value = @key ? record[@key] : 1 # ignore if record value is nil return if value.nil? @counter.increment(labels(record, ), value) end |