]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - config/updxlrator/lscache
3 # This code is distributed under the terms of the GPL
5 # (c) 2006-2008 marco.s - http://update-accelerator.advproxy.net
7 # $Id: lscache,v 1.0 2007/09/11 00:00:00 marco.s Exp $
13 my $swroot='/var/ipfire';
14 my $apphome="$swroot/updatexlrator";
15 my $repository='/var/updatecache';
36 my $maxlength_filesize=0;
37 my $maxlength_request=0;
38 my $maxlength_vendorid=0;
43 foreach (<$repository/*>)
47 unless ((/^$repository\/download
$/) || (/^$repository\
/lost\+found$/)) { push(@sources,$_); }
53 $vendorid=substr($_,rindex($_,'/')+1,length($_));
54 push(@vendors,$vendorid);
56 foreach $objectdir (@updatelist)
58 if (-e
"$objectdir/source.url")
60 open (FILE
,"$objectdir/source.url");
64 $updatefile = substr($sourceurl,rindex($sourceurl,'/')+1,length($sourceurl));
66 # Get filesize and calculate max length for output
68 $filesize = (-s
"$objectdir/$updatefile");
69 if (length($filesize) > $maxlength_filesize) { $maxlength_filesize = length($filesize); }
73 $totalfilesize += $filesize;
75 # File size for this source
77 $vendorstats{$vendorid . "_filesize"} += $filesize;
79 # Number of requests from cache for this source
81 open (FILE
,"$objectdir/access.log");
87 $vendorstats{$vendorid . "_requests"} += $counts;
88 $cachehits += $counts;
90 # Calculate cache hits max length for output
92 if (length($cachehits) > $maxlength_request) { $maxlength_request = length($cachehits); }
94 # Get last cache access date
96 my ($SECdt,$MINdt,$HOURdt,$DAYdt,$MONTHdt,$YEARdt) = localtime($requests[-1]);
97 $DAYdt = sprintf ("%.02d",$DAYdt);
98 $MONTHdt = sprintf ("%.02d",$MONTHdt+1);
99 $YEARdt = sprintf ("%.04d",$YEARdt+1900);
100 if (($counts) && ($requests[-1] =~ /^\d+/) && ($requests[-1] >= 1))
102 $lastaccess = $YEARdt."-".$MONTHdt."-".$DAYdt;
107 # Get file modification time
109 ($SECdt,$MINdt,$HOURdt,$DAYdt,$MONTHdt,$YEARdt) = localtime(&getmtime
("$objectdir/$updatefile"));
110 $DAYdt = sprintf ("%.02d",$DAYdt);
111 $MONTHdt = sprintf ("%.02d",$MONTHdt+1);
112 $YEARdt = sprintf ("%.04d",$YEARdt+1900);
113 $filedate = $YEARdt."-".$MONTHdt."-".$DAYdt;
115 # Total number of files in cache
119 # Number of files for this source
121 $vendorstats{$vendorid . "_files"}++;
123 # Count cache status occurences
125 open (FILE
,"$objectdir/status");
129 $vendorstats{$vendorid . "_" . $_}++;
131 # Calculate cached traffic for this source
133 $vendorstats{$vendorid . "_cachehits"} += $counts * $filesize;
135 # Calculate total cached traffic
137 $cachedtraffic += $counts * $filesize;
139 # Calculate vendor ID max length for output
141 if (length($vendorid) > $maxlength_vendorid) { $maxlength_vendorid = length($vendorid); }
143 # Add record to filelist
145 push (@filelist,"$filesize;$filedate;$counts;$lastaccess;$vendorid;$objectdir;$updatefile");
150 @filelist || die "No matching files found in cache\n";
153 # Process statistics for output
156 if ($Getopt::Std
::opt_s
)
161 printf "%5d %s", $vendorstats{$_ . "_files"}, "files in cache\n";
162 printf "%5d %s", $vendorstats{$_ . "_requests"}, "files from cache\n";
163 printf "%5d %s", $vendorstats{$_ . "_1"}, "files 'Ok'\n";
164 printf "%5d %s", $vendorstats{$_ . "_3"}, "files 'No source'\n";
165 printf "%5d %s", $vendorstats{$_ . "_2"}, "files 'Outdated'\n";
166 printf "%5d %s", $vendorstats{$_ . "_0"}, "files 'Unknown'\n";
167 unless ($vendorstats{$_ . "_filesize"}) { $vendorstats{$_ . "_filesize"} = '0'; }
168 1 while $vendorstats{$_ . "_filesize"} =~ s/^(-?\d+)(\d{3})/$1.$2/;
169 printf "%15s %s", $vendorstats{$_ . "_filesize"}, "bytes in cache\n";
170 unless ($vendorstats{$_ . "_cachehits"}) { $vendorstats{$_ . "_cachehits"} = '0'; }
171 1 while $vendorstats{$_ . "_cachehits"} =~ s/^(-?\d+)(\d{3})/$1.$2/;
172 printf "%15s %s", $vendorstats{$_ . "_cachehits"}, "bytes from cache\n\n";
175 if ($numfiles) { $efficiency = sprintf("%.1f", $cachehits / $numfiles); }
176 1 while $totalfilesize =~ s/^(-?\d+)(\d{3})/$1.$2/;
177 1 while $cachedtraffic =~ s/^(-?\d+)(\d{3})/$1.$2/;
178 print "\nTotal files in cache: $numfiles\n";
179 print "Total cache size: $totalfilesize bytes\n";
180 print "Delivered from cache: $cachedtraffic bytes\n";
181 print "Cache efficiency index: $efficiency\n";
187 # Process filelist for output
193 printf "%$maxlength_filesize\d %s ",$tmp[0],$tmp[1];
194 if ($Getopt::Std
::opt_a
) { printf "%$maxlength_request\d %s ",$tmp[2],$tmp[3]; }
195 if ($Getopt::Std
::opt_d
) { printf "%-$maxlength_vendorid\s ",$tmp[4]; }
196 if ($Getopt::Std
::opt_f
) { print "$tmp[5]/"; }
201 # -------------------------------------------------------------------
205 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($_[0]);
210 # -------------------------------------------------------------------
214 $Getopt::Std
::STANDARD_HELP_VERSION
=1;
216 lscache (Update Accelerator coreutils) 1.00
217 Copyright (c) 2006-2008 marco.s - http://update-accelerator.advproxy.net
222 # -------------------------------------------------------------------
228 Usage: lscache [-adf | -s]
230 Shows details about the Update Accelerator cache content
233 -a list number of cache hits and last access date
234 -d list download source
235 -f list full cache path
238 -s show statistics by source
240 --help display this help
241 --version output version information
246 # -------------------------------------------------------------------