Class: Fluent::Plugin::Prometheus::Histogram
- Defined in:
- lib/fluent/plugin/prometheus.rb
Instance Attribute Summary
Attributes inherited from Metric
Instance Method Summary collapse
-
#initialize(element, registry, labels) ⇒ Histogram
constructor
A new instance of Histogram.
- #instrument(record, expander) ⇒ Object
Methods inherited from Metric
Constructor Details
#initialize(element, registry, labels) ⇒ Histogram
Returns a new instance of Histogram.
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/fluent/plugin/prometheus.rb', line 370 def initialize(element, registry, labels) super if @key.nil? raise ConfigError, "histogram metric requires 'key' option" end begin if element['buckets'] buckets = element['buckets'].split(/,/).map(&:strip).map do |e| e[/\A\d+.\d+\Z/] ? e.to_f : e.to_i end @histogram = registry.histogram(element['name'].to_sym, docstring: element['desc'], labels: @base_labels.keys, buckets: buckets) else @histogram = registry.histogram(element['name'].to_sym, docstring: element['desc'], labels: @base_labels.keys) end rescue ::Prometheus::Client::Registry::AlreadyRegisteredError @histogram = Fluent::Plugin::Prometheus::Metric.get(registry, element['name'].to_sym, :histogram, element['desc']) end if @initialized Fluent::Plugin::Prometheus::Metric.init_label_set(@histogram, @base_initlabels, @base_labels) end end |
Instance Method Details
#instrument(record, expander) ⇒ Object
394 395 396 397 398 399 400 401 402 403 |
# File 'lib/fluent/plugin/prometheus.rb', line 394 def instrument(record, ) if @key.is_a?(String) value = record[@key] else value = @key.call(record) end if value @histogram.observe(value, labels: labels(record, )) end end |