Index: trunk/wikistats/dammit.lt/DammitPatchProjectcountsFromSquidStats.pl |
— | — | @@ -0,0 +1,88 @@ |
| 2 | +#!/usr/bin/perl
|
| 3 | +
|
| 4 | +$| = 1; # flush screen output
|
| 5 | +
|
| 6 | +open IN, '<', 'SquidDataHourlyAverageDeltaSequenceNumbers.csv' ; # collected on locke via SquidsLoadScan.pl
|
| 7 | +open LOG, '>', 'SquidDataHourlyAverageDeltaSequenceNumbersLog.txt' ;
|
| 8 | +
|
| 9 | +$path_projectcounts = "DammitPatchProjectcountsForServerOverload2011" ;
|
| 10 | +chdir ($path_projectcounts) || die "Cannot chdir to $path_projectcounts\n" ;
|
| 11 | +
|
| 12 | +while ($line = <IN>)
|
| 13 | +{
|
| 14 | + chomp $line ;
|
| 15 | +
|
| 16 | + next if $line !~ /^2011/ ;
|
| 17 | +
|
| 18 | + ($date,$hour,$avg_delta) = split (',', $line) ;
|
| 19 | +
|
| 20 | + next if $avg_delta <= 1005 ; # normally projectcounts also miss a few hits, overcorrecting would skew trends
|
| 21 | + &Patch ($date, $hour, $avg_delta) ;
|
| 22 | + print "$date,$hour,$avg_delta\n" ;
|
| 23 | +}
|
| 24 | +
|
| 25 | +print "\n\nReady\n\n" ;
|
| 26 | +exit ;
|
| 27 | +
|
| 28 | +sub Patch
|
| 29 | +{
|
| 30 | + ($date,$hour,$avg_delta) = @_ ;
|
| 31 | +
|
| 32 | + $date =~ s/-//g ;
|
| 33 | + $file = "projectcounts-$date-" . sprintf ("%02d",$hour) . "0000" ;
|
| 34 | +
|
| 35 | + if (! -e $file)
|
| 36 | + {
|
| 37 | + $file = "projectcounts-$date-" . sprintf ("%02d",$hour) . "0001" ;
|
| 38 | + if (! -e $file)
|
| 39 | + {
|
| 40 | + print "File '$file' missing!\n" ;
|
| 41 | + }
|
| 42 | + return ;
|
| 43 | + }
|
| 44 | +
|
| 45 | + &PatchFile ($file, $avg_delta) ;
|
| 46 | +}
|
| 47 | +
|
| 48 | +sub PatchFile
|
| 49 | +{
|
| 50 | + my ($file,$avg_delta) = @_ ;
|
| 51 | + my $line ;
|
| 52 | + $correction = $avg_delta / 1000 ;
|
| 53 | +
|
| 54 | + print "Patch file $file: avg delta $avg_delta -> correction $correction\n" ;
|
| 55 | +
|
| 56 | + undef @projectfile ;
|
| 57 | + $file_changed = 0 ;
|
| 58 | +
|
| 59 | + open PROJECTFILE, '<', $file || die "Could not open '$file'\n" ;
|
| 60 | + while ($line = <PROJECTFILE>)
|
| 61 | + {
|
| 62 | + chomp $line ;
|
| 63 | + ($project,$dash,$count,$bytes) = split (' ', $line) ;
|
| 64 | +
|
| 65 | + if ($bytes > 0)
|
| 66 | + {
|
| 67 | + $count = sprintf ("%.0f", $correction * $count) ;
|
| 68 | + # &Log ("\n$line ->\n") ;
|
| 69 | + $line = "$project $dash $count 1" ; # store 1 instead of 'bytes sent' to indicate file has been patched
|
| 70 | + # &Log ("$line\n") ;
|
| 71 | + }
|
| 72 | + push @projectfile, "$line\n" ;
|
| 73 | + }
|
| 74 | + close PROJECTFILE ;
|
| 75 | +
|
| 76 | + open PROJECTFILE, '>', $file || die "Could not open '$file'\n" ;
|
| 77 | + print PROJECTFILE @projectfile ;
|
| 78 | + close PROJECTFILE ;
|
| 79 | +}
|
| 80 | +
|
| 81 | +sub Log
|
| 82 | +{
|
| 83 | + my $msg = shift ;
|
| 84 | + print $msg ;
|
| 85 | + print LOG $msg ;
|
| 86 | +}
|
| 87 | +
|
| 88 | +
|
| 89 | +
|