Sha256: 9ad1ce9b630b711636ea6e378d276df428d209d2f4836503e8b59b8bd030c2c0

Contents?: true

Size: 729 Bytes

Versions: 1

Compression:

Stored size: 729 Bytes

Contents

module FluentLoggerStatistics
  class App
    include Rack::Utils

    def initialize(fluent_logger)
      @fluent_logger = fluent_logger
    end

    ACCEPT_METHODS = ['GET'].freeze

    def call(env)
      unless ACCEPT_METHODS.include?(env['REQUEST_METHOD'])
        return [404, {'Content-Type' => 'text/plain'}, []]
      end

      status = 200
      header = {'Content-Type' => 'application/json'}

      bytesize = @fluent_logger.pending_bytesize
      limit = @fluent_logger.limit
      usage_rate = bytesize / limit.to_f

      body = [
        { buffer_bytesize: bytesize,
          buffer_limit: limit,
          buffer_usage_rate: usage_rate
        }.to_json
      ]

      [status, header, body]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent_logger_statistics-0.2.0 lib/fluent_logger_statistics/app.rb