Skip to content

Instantly share code, notes, and snippets.

@kszarek
Created March 1, 2016 21:14
Show Gist options
  • Save kszarek/298417d0910ae5b9b9e1 to your computer and use it in GitHub Desktop.
Save kszarek/298417d0910ae5b9b9e1 to your computer and use it in GitHub Desktop.
Perl script to get uniq IP by path from heroku logs
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
# cat 2016-02-29.timeout.log|./timeouts-webapp-by-url-ip.pl>2016-02-29.timeouts_path_uniq.csv
my $a;
while (<>) {
if (/path="(\S+?("|\?|\/\d+?)).+fwd="(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/) {
my ($path,$ip) = ($1,$3);
$a->{$path}->{'uniq_ip'}++ if !exists $a->{$path}->{$ip};
$a->{$path}->{$ip}++;
}
}
foreach my $path (sort keys %{$a}){
print "$path,$a->{$path}->{'uniq_ip'}\n";
}
# print Dumper($a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment