Class: Fluent::Plugin::Prometheus::Gauge
- Defined in:
- lib/fluent/plugin/prometheus.rb
Instance Attribute Summary
Attributes inherited from Metric
Instance Method Summary collapse
-
#initialize(element, registry, labels) ⇒ Gauge
constructor
A new instance of Gauge.
- #instrument(record, expander) ⇒ Object
Methods inherited from Metric
Constructor Details
#initialize(element, registry, labels) ⇒ Gauge
Returns a new instance of Gauge.
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/fluent/plugin/prometheus.rb', line 279 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) rescue ::Prometheus::Client::Registry::AlreadyRegisteredError @gauge = Fluent::Plugin::Prometheus::Metric.get(registry, element['name'].to_sym, :gauge, element['desc']) end if @initialized Fluent::Plugin::Prometheus::Metric.init_label_set(@gauge, @base_initlabels, @base_labels) end end |
Instance Method Details
#instrument(record, expander) ⇒ Object
296 297 298 299 300 301 302 303 304 305 |
# File 'lib/fluent/plugin/prometheus.rb', line 296 def instrument(record, ) if @key.is_a?(String) value = record[@key] else value = @key.call(record) end if value @gauge.set(value, labels: labels(record, )) end end |