Sha256: e2846d1921d15408076957b0b0b265689425433b63a6c5f5c747caf3a7d9d98d

Contents?: true

Size: 1.03 KB

Versions: 9

Compression:

Stored size: 1.03 KB

Contents

require 'net/http/server'
require 'json'

module Riemann
  module Babbler

    class Responder


      include Riemann::Babbler::Logging
      include Riemann::Babbler::Options

      attr_accessor :port, :errors, :config, :started_at

      def initialize
        @port       = opts.riemann.responder_port
        @started_at = Time.now.to_i
        @errors     = opts.errors
        @config     = opts.riemann
      end

      def info
        {
            :version => Riemann::Babbler::VERSION,
            :ruby    => "#{RUBY_VERSION}-#{RUBY_PATCHLEVEL}",
            :uptime  => Time.now.to_i - started_at,
            :errors  => errors.to_hash,
            :config  => config.to_hash
        }
      end

      def run!
        Thread.new {
          log :unknown, "Start responder 0.0.0.0:#{port}"
          Net::HTTP::Server.run(:port => port) do |request, _|
            log :debug, "Responder request: #{request}"
            [200, { 'Content-Type' => 'application/json' }, [info.to_json]]
          end
        }
      end
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
riemann-babbler-2.0.0pre9 lib/riemann/babbler/responder.rb
riemann-babbler-2.0.0pre8 lib/riemann/babbler/responder.rb
riemann-babbler-2.0.0pre7 lib/riemann/babbler/responder.rb
riemann-babbler-2.0.0pre6 lib/riemann/babbler/responder.rb
riemann-babbler-2.0.0pre5 lib/riemann/babbler/responder.rb
riemann-babbler-2.0.0pre4 lib/riemann/babbler/responder.rb
riemann-babbler-2.0.0pre3 lib/riemann/babbler/responder.rb
riemann-babbler-2.0.0pre2 lib/riemann/babbler/responder.rb
riemann-babbler-2.0.0pre1 lib/riemann/babbler/responder.rb