Sha256: 363cefff846831c38cb82c9302eefe31f5a096f35e5b2a3f818e023346068d42

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

require 'fluent/plugin/prometheus'
require 'fluent/plugin/filter'

module Fluent::Plugin
  class PrometheusFilter < Fluent::Plugin::Filter
    Fluent::Plugin.register_filter('prometheus', self)
    include Fluent::Plugin::PrometheusLabelParser
    include Fluent::Plugin::Prometheus

    helpers :thread

    def initialize
      super
      @registry = ::Prometheus::Client.registry
    end

    def multi_workers_ready?
      true
    end

    def configure(conf)
      super
      labels = parse_labels_elements(conf)
      @metrics = Fluent::Plugin::Prometheus.parse_metrics_elements(conf, @registry, labels)
    end

    def start
      super
      Fluent::Plugin::Prometheus.start_retention_threads(
        @metrics,
        @registry,
        method(:thread_create),
        method(:thread_current_running?),
        @log
      )
      Fluent::Plugin::Prometheus.start_reset_threads(
        @metrics,
        @registry,
        method(:thread_create),
        method(:thread_current_running?),
        @log
      )
    end

    def filter(tag, time, record)
      instrument_single(tag, time, record, @metrics)
      record
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
phihos-fluent-plugin-prometheus-2.0.3.pre.1 lib/fluent/plugin/filter_prometheus.rb