Class: Mayu::Metrics::Exporter::Server

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/mayu/metrics/exporter.rb

Class Method Summary collapse

Class Method Details

.setup(endpoint:, registry:) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/mayu/metrics/exporter.rb', line 15

def self.setup(endpoint:, registry:)
  Console.logger.info(
    self,
    "Starting metrics exporter on #{endpoint.to_url}"
  )

  Async::HTTP::Server.for(
    endpoint,
    protocol: Async::HTTP::Protocol::HTTP11
  ) do |request|
    if request.path == "/favicon.ico"
      next(
        Protocol::HTTP::Response[
          404,
          { "content-type": "text/plain" },
          ["Not found"]
        ]
      )
    end

    body = Prometheus::Client::Formats::Text.marshal(registry)

    Protocol::HTTP::Response[
      200,
      { "content-type": "text/plain" },
      [body]
    ]
  end
end