Sha256: 632052d7539495c5bd670816c291571be66ba67bced06bd6839192a74796ef3d

Contents?: true

Size: 640 Bytes

Versions: 1

Compression:

Stored size: 640 Bytes

Contents

require 'socket'
require 'json'

class Riemann::Responder

  def info
    {
      :version => Riemann::Babbler::VERSION,
      :ruby => "#{RUBY_VERSION}-#{RUBY_PATCHLEVEL}",
      :uptime => (Time.now.to_i - @started_at)
    }.to_json
  end

  def initialize( port = 55755 )
    @port = port
    @started_at = Time.now.to_i
  end

  def start
    @worker_thread = Thread.new {
      Socket.tcp_server_loop(@port) do |sock, _|
        begin
          sock.puts info
        ensure
          sock.close
        end
      end
    }
  end

  def stop
    if @worker_thread
      @worker_thread.kill
      @worker_thread = nil
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
riemann-babbler-1.2.0 lib/riemann/babbler/support/responder.rb