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.anu.edu.au
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;
76 @path = split(/\//, $file);
79 for ($i=0; $i <= $#path && $i <= $opt_l;$i++) {
80 $pathkey = $pathkey . "/" . $path[$i];
83 next if (substr($pathkey,0,length("$opt_s")) ne "$opt_s");
87 @address = split(/\./, $host);
89 $domain = $address[$#address];
90 if ( int($address[0]) > 0 || $#address < 2 )
91 { $domain = "unresolved"; }
94 next unless (substr($domain,0,length("$opt_D")) eq "$opt_D");
98 # printf ("c=%d day=%s bytes=%d file=%s path=%s\n",
99 # $#line, $daytime, $bytes, $file, $pathkey);
101 $xferfiles++; # total files sent
102 $xfertfiles++; # total files sent
103 $xferfiles{$daytime}++; # files per day
104 $groupfiles{$pathkey}++; # per-group accesses
105 $domainfiles{$domain}++;
107 $xferbytes{$daytime} += $bytes; # bytes per day
108 $domainbytes{$domain} += $bytes; # xmit bytes to domain
109 $xferbytes += $bytes; # total bytes sent
110 $groupbytes{$pathkey} += $bytes; # per-group bytes sent
112 $xfertfiles{$hour}++; # files per hour
113 $xfertbytes{$hour} += $bytes; # bytes per hour
114 $xfertbytes += $bytes; # total bytes sent
118 @syslist = keys(systemfiles);
119 @dates = sort datecompare keys(xferbytes);
121 if ($xferfiles == 0) {die "There was no data to process.\n";}
124 print "TOTALS FOR SUMMARY PERIOD ", $dates[0], " TO ", $dates[$#dates], "\n\n";
125 printf ("Files Transmitted During Summary Period %12.0f\n", $xferfiles);
126 printf ("Bytes Transmitted During Summary Period %12.0f\n", $xferbytes);
127 printf ("Systems Using Archives %12.0f\n\n", $#syslist+1);
129 printf ("Average Files Transmitted Daily %12.0f\n",
130 $xferfiles / ($#dates + 1));
131 printf ("Average Bytes Transmitted Daily %12.0f\n",
132 $xferbytes / ($#dates + 1));
136 Daily Transmission Statistics
138 Number Of Number of Percent Of Percent Of
139 Date Files Sent MB Sent Files Sent Bytes Sent
140 --------------- ---------- ----------- ---------- ----------
144 @<<<<<<<<<<<<<< @>>>>>>>>> @>>>>>>>>>> @>>>>>>> @>>>>>>>
145 $date, $nfiles, $nbytes/(1024*1024), $pctfiles, $pctbytes
151 foreach $date ( sort datecompare keys(xferbytes) ) {
153 $nfiles = $xferfiles{$date};
154 $nbytes = $xferbytes{$date};
155 $pctfiles = sprintf("%8.2f", 100*$xferfiles{$date} / $xferfiles);
156 $pctbytes = sprintf("%8.2f", 100*$xferbytes{$date} / $xferbytes);
163 Total Transfers from each Archive Section (By bytes)
166 Archive Section NFiles MB Files Bytes
167 ------------------------------------- ------- ----------- ----- -------
171 @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>> @>>>>>>>>>> @>>>> @>>>>
172 $section, $files, $bytes/(1024*1024), $pctfiles, $pctbytes
180 foreach $section ( sort bytecompare keys(groupfiles) ) {
182 $files = $groupfiles{$section};
183 $bytes = $groupbytes{$section};
184 $pctbytes = sprintf("%8.2f", 100 * $groupbytes{$section} / $xferbytes);
185 $pctfiles = sprintf("%8.2f", 100 * $groupfiles{$section} / $xferfiles);
190 if ( $xferfiles < 1 ) { $xferfiles = 1; }
191 if ( $xferbytes < 1 ) { $xferbytes = 1; }
197 Total Transfer Amount By Domain
199 Number Of Number of Percent Of Percent Of
200 Domain Name Files Sent MB Sent Files Sent Bytes Sent
201 ----------- ---------- ------------ ---------- ----------
205 @<<<<<<<<<< @>>>>>>>>> @>>>>>>>>>>> @>>>>>>> @>>>>>>>
206 $domain, $files, $bytes/(1024*1024), $pctfiles, $pctbytes
213 foreach $domain ( sort domnamcompare keys(domainfiles) ) {
215 if ( $domainsecs{$domain} < 1 ) { $domainsecs{$domain} = 1; }
217 $files = $domainfiles{$domain};
218 $bytes = $domainbytes{$domain};
219 $pctfiles = sprintf("%8.2f", 100 * $domainfiles{$domain} / $xferfiles);
220 $pctbytes = sprintf("%8.2f", 100 * $domainbytes{$domain} / $xferbytes);
231 Hourly Transmission Statistics
233 Number Of Number of Percent Of Percent Of
234 Time Files Sent MB Sent Files Sent Bytes Sent
235 --------------- ---------- ----------- ---------- ----------
239 @<<<<<<<<<<<<<< @>>>>>>>>> @>>>>>>>>>> @>>>>>>> @>>>>>>>
240 $hour, $nfiles, $nbytes/(1024*1024), $pctfiles, $pctbytes
249 foreach $hour ( sort keys(xfertbytes) ) {
251 $nfiles = $xfertfiles{$hour};
252 $nbytes = $xfertbytes{$hour};
253 $pctfiles = sprintf("%8.2f", 100*$xfertfiles{$hour} / $xferfiles);
254 $pctbytes = sprintf("%8.2f", 100*$xfertbytes{$hour} / $xferbytes);
266 $sdiff = length($a) - length($b);
267 ($sdiff < 0) ? -1 : ($sdiff > 0) ? 1 : ($a lt $b) ? -1 : ($a gt $b) ? 1 : 0;
273 $bdiff = $groupbytes{$b} - $groupbytes{$a};
274 ($bdiff < 0) ? -1 : ($bdiff > 0) ? 1 : ($a lt $b) ? -1 : ($a gt $b) ? 1 : 0;
280 $fdiff = $fac{$b} - $fac{$a};
281 ($fdiff < 0) ? -1 : ($fdiff > 0) ? 1 : ($a lt $b) ? -1 : ($a gt $b) ? 1 : 0;