Class: Fluent::Plugin::PrometheusInput

Inherits:
Input
  • Object
show all
Defined in:
lib/fluent/plugin/in_prometheus.rb

Defined Under Namespace

Classes: MonitorServlet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePrometheusInput

Returns a new instance of PrometheusInput.



34
35
36
37
# File 'lib/fluent/plugin/in_prometheus.rb', line 34

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

Instance Attribute Details

#registryObject (readonly)

Returns the value of attribute registry.



32
33
34
# File 'lib/fluent/plugin/in_prometheus.rb', line 32

def registry
  @registry
end

Instance Method Details

#configure(conf) ⇒ Object



39
40
41
42
# File 'lib/fluent/plugin/in_prometheus.rb', line 39

def configure(conf)
  super
  @port += fluentd_worker_id
end

#multi_workers_ready?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/fluent/plugin/in_prometheus.rb', line 44

def multi_workers_ready?
  true
end

#shutdownObject



90
91
92
93
94
95
96
# File 'lib/fluent/plugin/in_prometheus.rb', line 90

def shutdown
  if @server
    @server.shutdown
    @server = nil
  end
  super
end

#startObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/fluent/plugin/in_prometheus.rb', line 48

def start
  super
  log.debug "listening prometheus http server on http://#{@bind}:#{@port}/#{@metrics_path} for worker#{fluentd_worker_id}"
  config = {
    BindAddress: @bind,
    Port: @port,
    MaxClients: 5,
    Logger: WEBrick::Log.new(STDERR, WEBrick::Log::FATAL),
    AccessLog: [],
  }
  unless @ssl.nil? || !@ssl['enable']
    require 'webrick/https'
    require 'openssl'
    if (@ssl['certificate_path'] && @ssl['private_key_path'].nil?) || (@ssl['certificate_path'].nil? && @ssl['private_key_path'])
        raise RuntimeError.new("certificate_path and private_key_path most both be defined")
    end
    ssl_config = {
        SSLEnable: true
    }
    if @ssl['certificate_path']
      cert = OpenSSL::X509::Certificate.new(File.read(@ssl['certificate_path']))
      ssl_config[:SSLCertificate] = cert
    end
    if @ssl['private_key_path']
      key = OpenSSL::PKey::RSA.new(File.read(@ssl['private_key_path']))
      ssl_config[:SSLPrivateKey] = key
    end
    ssl_config[:SSLCACertificateFile] = @ssl['ca_path'] if @ssl['ca_path']
    ssl_config = ssl_config.merge(@ssl['extra_conf'])
    config = ssl_config.merge(config)
  end
  @log.on_debug do
    @log.debug("WEBrick conf: #{config}")
  end

  @server = WEBrick::HTTPServer.new(config)
  @server.mount(@metrics_path, MonitorServlet, self)
  thread_create(:in_prometheus) do
    @server.start
  end
end