Class: Fluent::Plugin::PrometheusPushgatewayOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_prometheus_pushgateway.rb

Instance Method Summary collapse

Constructor Details

#initializePrometheusPushgatewayOutput

Returns a new instance of PrometheusPushgatewayOutput.



60
61
62
63
64
# File 'lib/fluent/plugin/out_prometheus_pushgateway.rb', line 60

def initialize
  super

  @registry = ::Prometheus::Client.registry
end

Instance Method Details

#configure(conf) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/fluent/plugin/out_prometheus_pushgateway.rb', line 70

def configure(conf)
  super

  if Prometheus::Client::VERSION.split(".")[0].to_i >= 3
    grouping_key = @instance ? {instance: @instance} : {}
    @push_client = ::Prometheus::Client::Push.new(job: "#{@job_name}:#{fluentd_worker_id}", grouping_key: grouping_key, gateway: @gateway)
  else
    @push_client = ::Prometheus::Client::Push.new("#{@job_name}:#{fluentd_worker_id}", @instance, @gateway)
  end

  use_tls = gateway && (URI.parse(gateway).scheme == 'https')

  if use_tls
    # prometheus client doesn't have an interface to set the HTTPS options
    http = @push_client.instance_variable_get(:@http)
    if http.nil?
      log.warn("prometheus client ruby's version unmatched. https setting is ignored")
    end

    # https://github.com/ruby/ruby/blob/dec802d8b59900e57e18fa6712caf95f12324aea/lib/net/http.rb#L599-L604
    tls_options.each do |k, v|
      http.__send__("#{k}=", v)
    end
  end
end

#multi_workers_ready?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/fluent/plugin/out_prometheus_pushgateway.rb', line 66

def multi_workers_ready?
  true
end

#process(tag, es) ⇒ Object



104
105
106
# File 'lib/fluent/plugin/out_prometheus_pushgateway.rb', line 104

def process(tag, es)
  # nothing
end

#startObject



96
97
98
99
100
101
102
# File 'lib/fluent/plugin/out_prometheus_pushgateway.rb', line 96

def start
  super

  timer_execute(:out_prometheus_pushgateway, @push_interval) do
    @push_client.add(@registry)
  end
end