Skip to content

Instantly share code, notes, and snippets.

@richardjharris
Created April 1, 2013 22:12
Show Gist options
  • Save richardjharris/5288203 to your computer and use it in GitHub Desktop.
Save richardjharris/5288203 to your computer and use it in GitHub Desktop.
Identify gaps in logs
#!/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