Skip to content

Instantly share code, notes, and snippets.

@drsnyder
Created July 17, 2012 19:16
Show Gist options
  • Save drsnyder/3131372 to your computer and use it in GitHub Desktop.
Save drsnyder/3131372 to your computer and use it in GitHub Desktop.
Simplistic estimate of varnish cache size
#!/usr/bin/perl
use strict;
my %object_map = {};
while (my $line = <>) {
if ($line =~ /.*?"GET (.*) HTTP\/\d\.\d" \d+ (\d+).*HIT/) {
my $url = $1;
my $size = $2;
$object_map{$url}{'size'} = $size;
$object_map{$url}{'count'}++;
#printf("Url: %s (%d)\n", $url, $size);
}
}
my $total = 0;
my $count = 0;
foreach my $key (keys %object_map) {
if ($object_map{$key}{'count'} > 1) {
$total += $object_map{$key}{'size'};
$count++;
}
}
printf("The total size of object requested: %2.2f MB\n", $total / 1048576);
printf("The total number of objects: %d\n", $count);
printf("The average size: %2.2fb\n", ($total / $count));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment