Added new IOERR_* defines.
[rsync.git] / support / rsyncstats
blob7e428e9eb4eeafad54939ce89533c3bd1832ba87
1 #! /usr/bin/perl
2 # ---------------------------------------------------------------------------
4 # USAGE: rsyncstats <options>
6 # 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.
31 $opt_h = 1;
32 $opt_d = 0;
33 $opt_t = 1;
34 $opt_l = 2;
36 require 'getopts.pl';
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";}
52 line: while (<LOG>) {
54 @line = split;
56 $day = $line[0];
57 $time = $line[1];
58 $pid = $line[2];
59 $op = $line[3];
60 $host = $line[4];
61 $ip = $line[5];
62 $module = $line[6];
63 $user = $line[7];
64 $file = $line[8];
65 $bytes = $line[9];
67 next if ($#line != 9);
69 next if ($op != "send" && $op != "recv");
71 $daytime = $day;
72 $hour = substr($time,0,2);
74 $file = $module . "/" . $file;
76 $file =~ s|//|/|mg;
78 @path = split(/\//, $file);
80 $pathkey = "";
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");
87 $host =~ tr/A-Z/a-z/;
89 @address = split(/\./, $host);
91 $domain = $address[$#address];
92 if ( int($address[0]) > 0 || $#address < 2 )
93 { $domain = "unresolved"; }
95 if ($opt_D) {
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
118 close LOG;
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));
136 format top1 =
138 Daily Transmission Statistics
140 Number Of Number of Percent Of Percent Of
141 Date Files Sent MB Sent Files Sent Bytes Sent
142 --------------- ---------- ----------- ---------- ----------
145 format line1 =
146 @<<<<<<<<<<<<<< @>>>>>>>>> @>>>>>>>>>> @>>>>>>> @>>>>>>>
147 $date, $nfiles, $nbytes/(1024*1024), $pctfiles, $pctbytes
150 $^ = top1;
151 $~ = line1;
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);
159 write;
162 if ($opt_t) {
163 format top2 =
165 Total Transfers from each Archive Section (By bytes)
167 - Percent -
168 Archive Section NFiles MB Files Bytes
169 ------------------------------------- ------- ----------- ----- -------
172 format line2 =
173 @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>> @>>>>>>>>>> @>>>> @>>>>
174 $section, $files, $bytes/(1024*1024), $pctfiles, $pctbytes
177 $| = 1;
178 $- = 0;
179 $^ = top2;
180 $~ = line2;
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);
188 write;
192 if ( $xferfiles < 1 ) { $xferfiles = 1; }
193 if ( $xferbytes < 1 ) { $xferbytes = 1; }
196 if ($opt_d) {
197 format top3 =
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 ----------- ---------- ------------ ---------- ----------
206 format line3 =
207 @<<<<<<<<<< @>>>>>>>>> @>>>>>>>>>>> @>>>>>>> @>>>>>>>
208 $domain, $files, $bytes/(1024*1024), $pctfiles, $pctbytes
211 $- = 0;
212 $^ = top3;
213 $~ = line3;
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);
223 write;
229 if ($opt_h) {
231 format top8 =
233 Hourly Transmission Statistics
235 Number Of Number of Percent Of Percent Of
236 Time Files Sent MB Sent Files Sent Bytes Sent
237 --------------- ---------- ----------- ---------- ----------
240 format line8 =
241 @<<<<<<<<<<<<<< @>>>>>>>>> @>>>>>>>>>> @>>>>>>> @>>>>>>>
242 $hour, $nfiles, $nbytes/(1024*1024), $pctfiles, $pctbytes
246 $| = 1;
247 $- = 0;
248 $^ = top8;
249 $~ = line8;
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);
257 write;
260 exit(0);
262 sub datecompare {
263 $a gt $b;
266 sub domnamcompare {
268 $sdiff = length($a) - length($b);
269 ($sdiff < 0) ? -1 : ($sdiff > 0) ? 1 : ($a lt $b) ? -1 : ($a gt $b) ? 1 : 0;
273 sub bytecompare {
275 $bdiff = $groupbytes{$b} - $groupbytes{$a};
276 ($bdiff < 0) ? -1 : ($bdiff > 0) ? 1 : ($a lt $b) ? -1 : ($a gt $b) ? 1 : 0;
280 sub faccompare {
282 $fdiff = $fac{$b} - $fac{$a};
283 ($fdiff < 0) ? -1 : ($fdiff > 0) ? 1 : ($a lt $b) ? -1 : ($a gt $b) ? 1 : 0;