Skip to content

Instantly share code, notes, and snippets.

@moretea
Created April 23, 2016 08:36
Show Gist options
  • Save moretea/750b981764c8e88a20db6e11e8a05911 to your computer and use it in GitHub Desktop.
Save moretea/750b981764c8e88a20db6e11e8a05911 to your computer and use it in GitHub Desktop.
Get the mesos log in your CLI.
require 'json'
require 'net/http'
require 'openssl'
MESOS_BASE_PATH = "https://hostname/path_to_mesos"
MESOS_USER = "<SOMEUSER>"
MESOS_PASSWORD = ""
def get(offset,length=500000)
_ = Time.now.to_i * 100 + 100
url = MESOS_BASE_PATH + "/files/read?path=/master/log&offset=#{offset}&length=#{length}&jsonp=&_=#{_}"
output = `curl -s -k -u #{MESOS_USER}:#{MESOS_PASSWORD} '#{url}'`.chomp
json = output[1..-3]
JSON.parse(json)["data"]
end
offset = 0
buffer = ""
loop do
new = get(offset)
if new.length == 0
sleep 1
next
else
offset += new.length
buffer += new
last_nl = buffer.rindex("\n")
if last_nl != nil
new_lines = buffer[0..last_nl]
buffer = buffer[(last_nl+1)..-1]
print new_lines
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment