Class: Fluent::Plugin::Prometheus::Counter
- Inherits:
-
Metric
- Object
- Metric
- Fluent::Plugin::Prometheus::Counter
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, #labels
Constructor Details
#initialize(element, registry, labels) ⇒ Counter
210
211
212
213
214
215
216
217
|
# File 'lib/fluent/plugin/prometheus.rb', line 210
def initialize(element, registry, labels)
super
begin
@counter = registry.counter(element['name'].to_sym, element['desc'])
rescue ::Prometheus::Client::Registry::AlreadyRegisteredError
@counter = Fluent::Plugin::Prometheus::Metric.get(registry, element['name'].to_sym, :counter, element['desc'])
end
end
|
Instance Method Details
#instrument(record, expander) ⇒ Object
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
# File 'lib/fluent/plugin/prometheus.rb', line 219
def instrument(record, expander)
if @key.nil?
value = 1
elsif @key.is_a?(String)
value = record[@key]
else
value = @key.call(record)
end
return if value.nil?
@counter.increment(labels(record, expander), value)
end
|