Created
April 1, 2013 22:12
-
-
Save richardjharris/5288203 to your computer and use it in GitHub Desktop.
Identify gaps in logs
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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use autodie ':io'; | |
use Time::Duration qw(duration); | |
use Date::Parse qw(str2time); | |
my $min_gap = shift || 3600; | |
my $prev; | |
while (my $line = <>) { | |
my $ts = parse_date($line); | |
if (defined $ts) { | |
if (defined $prev) { | |
my $delta = $ts - $prev; | |
if ($delta >= $min_gap) { | |
print "--- GAP: " . duration($delta) . " ---\n"; | |
} | |
} | |
$prev = $ts; | |
} | |
print $line; | |
} | |
sub parse_date { | |
my $line = shift; | |
$line =~ /^\[ ([^\[]+) \]/x or return; | |
my $ts = str2time($1); | |
return $ts; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment