Skip to content

Instantly share code, notes, and snippets.

@zoffixznet

zoffixznet/p6.p6 Secret

Created July 21, 2017 15:32
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 zoffixznet/380351b71f87cf158dc7d68cc8c63d3f to your computer and use it in GitHub Desktop.
Save zoffixznet/380351b71f87cf158dc7d68cc8c63d3f to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl6
sub MAIN(Real $start, Real $end, *@files) {
my %logs;
for IO::CatHandle.new(@files).lines -> $line {
my ($time, $, $domain, $, $status) = split ' | ', $line;
next unless $start$time$end;
%logs{$domain}<requests>++;
%logs{$domain}<errors>++ if 500$status < 600;
}
say "Between &human-date($start) and &human-date($end)";
for %logs.keys.sort -> $domain {
my $percent = (%logs{$domain}<errors>||0) / %logs{$domain}<requests> * 100;
say $domain.fmt("%16s") ~ " returned " ~ $percent.fmt("%.2f") ~ "% errors";
}
}
sub human-date {
DateTime.new: +$^timestamp, :formatter{
sprintf '%04d-%02d-%02d %02d:%02d:%02d',
.year, .month, .day, .hour, .minute, .second
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment