Skip to content

Instantly share code, notes, and snippets.

@tr4n2uil
Last active August 29, 2015 14:11
Show Gist options
  • Save tr4n2uil/d7a2cfe9157c4a18025f to your computer and use it in GitHub Desktop.
Save tr4n2uil/d7a2cfe9157c4a18025f to your computer and use it in GitHub Desktop.
slids = []
hash = {"not_working_users"=>0, "all_users" => 0, "error_messages" => 0, "ice_connection_failure"=>0, "not_connected_to_peer" => 0, "signal_did_not_get_client" => 0, "reconnect_with_data" => 0, 'reconnect_no_speed' => 0, 'reconnect_no_data_channel' => 0, 'server_not_connected' => 0, "no_logs" => 0, "doesn't_work_always" => 0}
all_users = []
not_working_users = []
SummaryLog.where("webrtc_state=3 and region='eu-west-1' and user_browser='firefox' and created_at between '2014-12-17' and '2014-12-18'").each do |sl|
content=`curl -s -u "admin:Ch0c0lat3s" -H "Content-Type: application/json" -H "Accept: application/json" "http://templog.browserstack.com/logs_json?live_session_id=#{sl.session_id}"`.strip
logs = JSON.parse(content)
messages = logs.map{|x| x["message"]}
if !(messages.include?("terminal_connected") || messages.include?("signalling_offer"))
hash['server_not_connected'] += 1
puts sl.session_id
end
all_users << sl.user_id
any_sessions = SummaryLog.where("user_id=#{sl.user_id}").order("id desc").limit(20)
working_sessions = any_sessions.find_all{|t| t.webrtc_state == 2}
if working_sessions.length == 0
not_working_users << sl.user_id
end
time_to_connect = nil
a = logs.find_all{|x| x["message"] == "webrtc_client_initializing"}.first
c = logs.find_all{|x| x["message"] == "client_connect_to_peer_server"}.first
h = logs.find_all{|x| x["message"] == "signalling_answer"}.first
b=c
d = logs.find_all{|x| x["message"] == "flash_fallback"}.first
e = logs.find_all{|x| x["message"] == "client_ice_state_change"}.first
f = logs.find_all{|x| x["message"] == "client_reconnecting_with_data"}.first
fn = logs.find_all{|x| x["message"] == "client_reconnecting"}.first
dn = logs.find_all{|x| x["message"] == "data_channel_open"}.first
cn = logs.find_all{|x| x["message"] == "webrtc_connection_data"}.first
g = logs.find_all{|x| x["app"] == "clientBrowser"}.length
time_to_connect = Time.parse(b["timestamp"]) - Time.parse(a["timestamp"]) if b && a
time_to_firstpacket = time_to_connect
post_ice_state = Time.parse(d["app_timestamp"]) - Time.parse(e["app_timestamp"]) if d && e
if working_sessions.length > 0 && g > 0
error_messages = logs.find_all{|x| x["error"].to_s != ""}.map{|x| x["message"]}
hash["error_messages"] += (error_messages.length > 0 ? 1 : 0)
if fn and cn.nil?
hash["reconnect_no_speed"] +=1
else
if f and dn.nil? and cn.nil?
hash["reconnect_no_data_channel"] += 1
end
end
if f
hash["reconnect_with_data"] +=1
reconnect = logs.find_all{|x| x["message"] == "Connected from webrtc"}.length > 0
else
if error_messages.length == 0 && post_ice_state && post_ice_state > 2.0
hash["ice_connection_failure"] += 1
slids << sl.session_id
end
hash["not_connected_to_peer"] += 1 if error_messages.length == 0 && time_to_connect.nil?
hash["signal_did_not_get_client"] += 1 if error_messages.length == 0 && c.nil? && h.nil?
end
elsif working_sessions.length == 0
hash["doesn't_work_always"] += 1
else
hash["no_logs"] += 1
end
puts "#{sl.id},#{sl.session_id},#{sl.region},#{time_to_connect},#{time_to_firstpacket},#{post_ice_state},#{error_messages.to_a.length},#{reconnect},#{working_sessions.to_a.length}/#{any_sessions.to_a.length},#{error_messages.to_a.join(',')}, #{!!a}"
end; nil
hash["not_working_users"] = not_working_users.uniq.length
hash["all_users"] = all_users.uniq.length
puts hash.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment