Class: Fluent::Plugin::Prometheus::Gauge

Inherits:
Metric
  • Object
show all
Defined in:
lib/fluent/plugin/prometheus.rb

Instance Attribute Summary

Attributes inherited from Metric

#desc, #key, #name, #retention, #retention_check_interval, #type

Instance Method Summary collapse

Methods inherited from Metric

get, #has_retention?, #instrument, #labels, #remove_expired_metrics, #set_value?

Constructor Details

#initialize(element, registry, labels) ⇒ Gauge

Returns a new instance of Gauge.



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/fluent/plugin/prometheus.rb', line 291

def initialize(element, registry, labels)
  super
  if @key.nil?
    raise ConfigError, "gauge metric requires 'key' option"
  end

  begin
    @gauge = registry.gauge(
      element['name'].to_sym,
      docstring: element['desc'],
      labels: @base_labels.keys,
      store_settings: { topk: @topk }
    )
  rescue ::Prometheus::Client::Registry::AlreadyRegisteredError
    @gauge = Fluent::Plugin::Prometheus::Metric.get(registry, element['name'].to_sym, :gauge, element['desc'])
  end
end

Instance Method Details

#set_value(value, labels) ⇒ Object



317
318
319
# File 'lib/fluent/plugin/prometheus.rb', line 317

def set_value(value, labels)
  @gauge.set(value, labels: labels)
end

#value(record) ⇒ Object



309
310
311
312
313
314
315
# File 'lib/fluent/plugin/prometheus.rb', line 309

def value(record)
  if @key.is_a?(String)
    record[@key]
  else
    @key.call(record)
  end
end