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, #labels

Constructor Details

#initialize(element, registry, labels) ⇒ Summary

Returns a new instance of Summary.



193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/fluent/plugin/prometheus.rb', line 193

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, element['desc'])
  rescue ::Prometheus::Client::Registry::AlreadyRegisteredError
    @summary = Fluent::Plugin::Prometheus::Metric.get(registry, element['name'].to_sym, :summary, element['desc'])
  end
end

Instance Method Details

#instrument(record, expander, placeholders) ⇒ Object



206
207
208
209
210
211
212
213
214
215
# File 'lib/fluent/plugin/prometheus.rb', line 206

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