2 # ---------------------------------------------------------------------------
4 # USAGE: rsyncstats <options>
7 # -f <filename> Use <filename> for the log file
8 # -h include report on hourly traffic
9 # -d include report on domain traffic
10 # -t report on total traffic by section
11 # -D <domain> report only on traffic from <domain>
12 # -l <depth> Depth of path detail for sections
13 # -s <section> Section to report on, For example: -s /pub will report
14 # only on paths under /pub
16 # This script parses the default logfile format produced by rsync when running
17 # as a daemon with transfer logging enabled. It is derived from the xferstats
18 # script that comes with wuftpd
20 # Andrew Tridgell, October 1998
21 # rsync-bugs@samba.org
23 # ---------------------------------------------------------------------------
25 # edit the next line to customize for your default log file
26 $usage_file = "/var/adm/rsyncd.log";
28 # Edit the following lines for default report settings.
29 # Entries defined here will be over-ridden by the command line.
37 &Getopts
('f:rahdD:l:s:');
39 if ($opt_r) { $real = 1;}
40 if ($opt_a) { $anon = 1;}
41 if ($real == 0 && $anon == 0) { $anon = 1; }
42 if ($opt_f) {$usage_file = $opt_f;}
44 open (LOG
,$usage_file) || die "Error opening usage log file: $usage_file\n";
46 if ($opt_D) {print "Transfer Totals include the '$opt_D' domain only.\n";
47 print "All other domains are filtered out for this report.\n\n";}
49 if ($opt_s) {print "Transfer Totals include the '$opt_s' section only.\n";
50 print "All other sections are filtered out for this report.\n\n";}
67 next if ($#line != 9);
69 next if ($op != "send" && $op != "recv");
72 $hour = substr($time,0,2);
74 $file = $module . "/" . $file;
78 @path = split(/\//, $file);
81 for ($i=0; $i <= $#path && $i <= $opt_l;$i++) {
82 $pathkey = $pathkey . "/" . $path[$i];
85 next if (substr($pathkey,0,length("$opt_s")) ne "$opt_s");
89 @address = split(/\./, $host);
91 $domain = $address[$#address];
92 if ( int($address[0]) > 0 || $#address < 2 )
93 { $domain = "unresolved"; }
96 next unless (substr($domain,0,length("$opt_D")) eq "$opt_D");
100 # printf ("c=%d day=%s bytes=%d file=%s path=%s\n",
101 # $#line, $daytime, $bytes, $file, $pathkey);
103 $xferfiles++; # total files sent
104 $xfertfiles++; # total files sent
105 $xferfiles{$daytime}++; # files per day
106 $groupfiles{$pathkey}++; # per-group accesses
107 $domainfiles{$domain}++;
109 $xferbytes{$daytime} += $bytes; # bytes per day
110 $domainbytes{$domain} += $bytes; # xmit bytes to domain
111 $xferbytes += $bytes; # total bytes sent
112 $groupbytes{$pathkey} += $bytes; # per-group bytes sent
114 $xfertfiles{$hour}++; # files per hour
115 $xfertbytes{$hour} += $bytes; # bytes per hour
116 $xfertbytes += $bytes; # total bytes sent
120 @syslist = keys(systemfiles
);
121 @dates = sort datecompare
keys(xferbytes
);
123 if ($xferfiles == 0) {die "There was no data to process.\n";}
126 print "TOTALS FOR SUMMARY PERIOD ", $dates[0], " TO ", $dates[$#dates], "\n\n";
127 printf ("Files Transmitted During Summary Period %12.0f\n", $xferfiles);
128 printf ("Bytes Transmitted During Summary Period %12.0f\n", $xferbytes);
129 printf ("Systems Using Archives %12.0f\n\n", $#syslist+1);
131 printf ("Average Files Transmitted Daily %12.0f\n",
132 $xferfiles / ($#dates + 1));
133 printf ("Average Bytes Transmitted Daily %12.0f\n",
134 $xferbytes / ($#dates + 1));
138 Daily Transmission Statistics
140 Number Of Number of Percent Of Percent Of
141 Date Files Sent MB Sent Files Sent Bytes Sent
142 --------------- ---------- ----------- ---------- ----------
146 @
<<<<<<<<<<<<<< @
>>>>>>>>> @
>>>>>>>>>> @
>>>>>>> @
>>>>>>>
147 $date, $nfiles, $nbytes/(1024*1024), $pctfiles, $pctbytes
153 foreach $date ( sort datecompare
keys(xferbytes
) ) {
155 $nfiles = $xferfiles{$date};
156 $nbytes = $xferbytes{$date};
157 $pctfiles = sprintf("%8.2f", 100*$xferfiles{$date} / $xferfiles);
158 $pctbytes = sprintf("%8.2f", 100*$xferbytes{$date} / $xferbytes);
165 Total Transfers from
each Archive Section
(By bytes
)
168 Archive Section NFiles MB Files Bytes
169 ------------------------------------- ------- ----------- ----- -------
173 @
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @
>>>>>> @
>>>>>>>>>> @
>>>> @
>>>>
174 $section, $files, $bytes/(1024*1024), $pctfiles, $pctbytes
182 foreach $section ( sort bytecompare
keys(groupfiles
) ) {
184 $files = $groupfiles{$section};
185 $bytes = $groupbytes{$section};
186 $pctbytes = sprintf("%8.2f", 100 * $groupbytes{$section} / $xferbytes);
187 $pctfiles = sprintf("%8.2f", 100 * $groupfiles{$section} / $xferfiles);
192 if ( $xferfiles < 1 ) { $xferfiles = 1; }
193 if ( $xferbytes < 1 ) { $xferbytes = 1; }
199 Total Transfer Amount By Domain
201 Number Of Number of Percent Of Percent Of
202 Domain Name Files Sent MB Sent Files Sent Bytes Sent
203 ----------- ---------- ------------ ---------- ----------
207 @
<<<<<<<<<< @
>>>>>>>>> @
>>>>>>>>>>> @
>>>>>>> @
>>>>>>>
208 $domain, $files, $bytes/(1024*1024), $pctfiles, $pctbytes
215 foreach $domain ( sort domnamcompare
keys(domainfiles
) ) {
217 if ( $domainsecs{$domain} < 1 ) { $domainsecs{$domain} = 1; }
219 $files = $domainfiles{$domain};
220 $bytes = $domainbytes{$domain};
221 $pctfiles = sprintf("%8.2f", 100 * $domainfiles{$domain} / $xferfiles);
222 $pctbytes = sprintf("%8.2f", 100 * $domainbytes{$domain} / $xferbytes);
233 Hourly Transmission Statistics
235 Number Of Number of Percent Of Percent Of
236 Time Files Sent MB Sent Files Sent Bytes Sent
237 --------------- ---------- ----------- ---------- ----------
241 @
<<<<<<<<<<<<<< @
>>>>>>>>> @
>>>>>>>>>> @
>>>>>>> @
>>>>>>>
242 $hour, $nfiles, $nbytes/(1024*1024), $pctfiles, $pctbytes
251 foreach $hour ( sort keys(xfertbytes
) ) {
253 $nfiles = $xfertfiles{$hour};
254 $nbytes = $xfertbytes{$hour};
255 $pctfiles = sprintf("%8.2f", 100*$xfertfiles{$hour} / $xferfiles);
256 $pctbytes = sprintf("%8.2f", 100*$xfertbytes{$hour} / $xferbytes);
268 $sdiff = length($a) - length($b);
269 ($sdiff < 0) ?
-1 : ($sdiff > 0) ?
1 : ($a lt $b) ?
-1 : ($a gt $b) ?
1 : 0;
275 $bdiff = $groupbytes{$b} - $groupbytes{$a};
276 ($bdiff < 0) ?
-1 : ($bdiff > 0) ?
1 : ($a lt $b) ?
-1 : ($a gt $b) ?
1 : 0;
282 $fdiff = $fac{$b} - $fac{$a};
283 ($fdiff < 0) ?
-1 : ($fdiff > 0) ?
1 : ($a lt $b) ?
-1 : ($a gt $b) ?
1 : 0;