Created
December 17, 2015 11:56
-
-
Save elia/52e174d5dac01587336b to your computer and use it in GitHub Desktop.
Connect to a Logentries log set and tail logs to the terminal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
warn "Usage: #{$0} ACCOUNT_KEY LOG_SET LOG_NAME" if ARGV.size != 3 | |
account_key = ARGV[0] | |
log_set = ARGV[1] | |
log_name = ARGV[2] | |
msec = -> t { (t.to_f * 1000).to_i } | |
now = Time.now | |
require 'thread' | |
require 'json' | |
raw_json_queue = Queue.new | |
json_queue = Queue.new | |
range_queue = Queue.new | |
message_queue = Queue.new | |
curl = -> ((starts, ends)) { | |
command = "curl -G https://pull.logentries.com/#{account_key}/hosts/#{log_set}/#{log_name}/ -d start=#{starts} -d end=#{ends} -d format=json 2> /dev/null" | |
IO.popen(command, 'r') { |io| io.read } | |
} | |
Thread.abort_on_exception = true | |
_printer = Thread.new { loop { puts message_queue.pop } } | |
_fetcher = Thread.new { loop { raw_json_queue << curl[range_queue.pop] } } | |
_parser = Thread.new { loop { json_queue << JSON.parse(raw_json_queue.pop, symbolize_names: true) } } | |
_router = Thread.new { loop { | |
last = json_queue.pop.entries.each {|entry| message_queue << entry[:m]}. | |
last[:t].to_i; | |
range_queue << [last, (last+1000)] | |
} } | |
range_queue << [msec[now - 15], msec[now - 13]] | |
sleep | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment