Skip to content

Instantly share code, notes, and snippets.

@jhamon
Created September 4, 2018 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhamon/414fac55b3075e857e70344c6514b8f8 to your computer and use it in GitHub Desktop.
Save jhamon/414fac55b3075e857e70344c6514b8f8 to your computer and use it in GitHub Desktop.
require 'date'
# The goal of this script is to identify log lines with a long time interval
# between log lines. Tune this by changing $seconds_between_log_lines
$seconds_between_log_lines = 4
$timestamp_regex = /\d+\-\d+\-\d+ \d+:\d+:\d+\.\d+/
def get_time(log_line)
if has_timestamp?(log_line)
time = DateTime.parse(log_line.scan($timestamp_regex)[0])
time.strftime('%s').to_i
else
0
end
end
def has_timestamp?(log_line)
!log_line.scan($timestamp_regex)[0].nil?
end
current_line = nil
previous_line = nil
IO.foreach("uaa.log") do |x|
next unless has_timestamp?(x)
if previous_line.nil?
previous_line = x
else
previous_line = current_line
end
current_line = x
if (get_time(previous_line) - get_time(current_line)).abs > $seconds_between_log_lines
puts '-------------'
print previous_line
print current_line
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment