Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

cleanup: tabs to space

SVN Revision: 426
  • Loading branch information...
commit a085fb8daa65dfe69d085ab64ab23c6d33307c2e 1 parent 9ae525d
Nicolas Niclausse nniclausse authored

Showing 1 changed file with 92 additions and 95 deletions. Show diff stats Hide diff stats

  1. +92 95 src/log2tsunami.pl.src
187 src/log2tsunami.pl.src
@@ -34,14 +34,14 @@ my %Months=('Jan','0', 'Feb','1', 'Mar','2', 'Apr','3', 'May','4', 'Jun','5',
34 34 my $tagvsn = '%VERSION%';
35 35
36 36 GetOptions( "help",\$help,
37   - "verbose",\$verbose,
38   - "tt=i",\$thinktime_threshold,
39   - "st=i",\$session_threshold,
40   - "visit_timeout=i",\$visit_timeout,
41   - "max_pages=i",\$max_pages,
42   - "max_duration=i",\$max_duration,
43   - "version",\$version
44   - );
  37 + "verbose",\$verbose,
  38 + "tt=i",\$thinktime_threshold,
  39 + "st=i",\$session_threshold,
  40 + "visit_timeout=i",\$visit_timeout,
  41 + "max_pages=i",\$max_pages,
  42 + "max_duration=i",\$max_duration,
  43 + "version",\$version
  44 + );
45 45
46 46 my $dtd ="%DTD%";
47 47
@@ -72,15 +72,15 @@ my $visit_tot=0;
72 72 &version if $version;
73 73
74 74 while (<>) {
75   - if (m@^([\w\.]+) \S+ \S+ \[(\w+/\w+/\w+:\d+:\d+:\d+)([^\]]+)\] \"(\w+) ([^\"]+)\" (\d+) (\S+) \"([^\"]*)\" \"([^\"]*)\"$@) {
76   - my $ip = $1;
77   - my $date = $2;
78   - my $code = $6;
79   - my $referer = $8;
80   - my $method = $4;
81   - my $user_agent = $9;
82   - my $req = $5;
83   - my ($url, $protocole) = split(/\s+/,$req);
  75 + if (m@^([\w\.]+) \S+ \S+ \[(\w+/\w+/\w+:\d+:\d+:\d+)([^\]]+)\] \"(\w+) ([^\"]+)\" (\d+) (\S+) \"([^\"]*)\" \"([^\"]*)\"$@) {
  76 + my $ip = $1;
  77 + my $date = $2;
  78 + my $code = $6;
  79 + my $referer = $8;
  80 + my $method = $4;
  81 + my $user_agent = $9;
  82 + my $req = $5;
  83 + my ($url, $protocole) = split(/\s+/,$req);
84 84 $url = &replace_entities($url);
85 85 my $version;
86 86 if ($protocole =~ /HTTP\/(\d\.\d)/) {
@@ -88,29 +88,28 @@ while (<>) {
88 88 } else {
89 89 $version="1.0";
90 90 }
91   -
92   - $date =~ m'(\d+)/(\w+)/(\d+):(\d+):(\d+):(\d+)';
93   - $mday = $1;
94   - $mon = $Months{$2};
95   - $year = $3 - 1900;
96   - $hour = $4;
97   - $min = $5;
98   - $sec = $6;
99   - $time = timelocal($sec,$min,$hour,$mday,$mon,$year);
  91 + $date =~ m'(\d+)/(\w+)/(\d+):(\d+):(\d+):(\d+)';
  92 + $mday = $1;
  93 + $mon = $Months{$2};
  94 + $year = $3 - 1900;
  95 + $hour = $4;
  96 + $min = $5;
  97 + $sec = $6;
  98 + $time = timelocal($sec,$min,$hour,$mday,$mon,$year);
100 99 $user = "$ip-$user_agent";
101   - if ($visite->{$user}) {
102   - if ($time - $visite->{$user}->{'last_visit'} > $visit_timeout) {
103   - # new visit
  100 + if ($visite->{$user}) {
  101 + if ($time - $visite->{$user}->{'last_visit'} > $visit_timeout) {
  102 + # new visit
104 103 $visit_tot ++;
105   - $visite->{$user}->{'id'}++;
106   - $id = $visite->{$user}->{'id'};
107   - $visite->{$user}->{'last_visit'}=$time;
108   - $visite->{$user}->{'last_referer'}=$referer;
109   - $visite->{$user}->{$id}->{'started'}=$time;
110   - $visite->{$user}->{$id}->{'last_request'}=$time;
111   - $visite->{$user}->{$id}->{'page'}=1;
112   - $visite->{$user}->{$id}->{'hit'}=1;
113   - $visite->{$user}->{$id}->{'duration'}=0;
  104 + $visite->{$user}->{'id'}++;
  105 + $id = $visite->{$user}->{'id'};
  106 + $visite->{$user}->{'last_visit'}=$time;
  107 + $visite->{$user}->{'last_referer'}=$referer;
  108 + $visite->{$user}->{$id}->{'started'}=$time;
  109 + $visite->{$user}->{$id}->{'last_request'}=$time;
  110 + $visite->{$user}->{$id}->{'page'}=1;
  111 + $visite->{$user}->{$id}->{'hit'}=1;
  112 + $visite->{$user}->{$id}->{'duration'}=0;
114 113 $visite->{$user}->{$id}->{'tsunami'} = '<session name="'.$ip."-".$id.'" type="ts_http">'."\n";
115 114 $visite->{$user}->{$id}->{'tsunami'} .= "\t".'<request><http url="'.$url.'" version="'.$version.'" method="'.$method.'"';
116 115 if ($code == 304) {
@@ -119,46 +118,44 @@ while (<>) {
119 118 $visite->{$user}->{$id}->{'tsunami'} .= '>';
120 119 }
121 120 $visite->{$user}->{$id}->{'tsunami'} .= "</http></request>\n";
122   - } else {
123   - # same visit
124   - $id = $visite->{$user}->{'id'};
125   - $visite->{$user}->{$id}->{'hit'}++;
126   - my $thinktime = $time - $visite->{$user}->{$id}->{'last_request'};
127   - $visite->{$user}->{'last_visit'}=$time;
128   - $visite->{$user}->{$id}->{'last_request'}=$time;
  121 + } else {
  122 + # same visit
  123 + $id = $visite->{$user}->{'id'};
  124 + $visite->{$user}->{$id}->{'hit'}++;
  125 + my $thinktime = $time - $visite->{$user}->{$id}->{'last_request'};
  126 + $visite->{$user}->{'last_visit'}=$time;
  127 + $visite->{$user}->{$id}->{'last_request'}=$time;
129 128 $visite->{$user}->{$id}->{'tsunami'} .= "\t".'<thinktime value="'.$thinktime.'"/>'."\n\n" if $thinktime > $thinktime_threshold;
130 129 $visite->{$user}->{$id}->{'tsunami'} .= "\t".'<request><http url="'.$url.'" version="'.$version.'" method="'.$method.'"></http></request>'."\n";
131   - # update duration
132   - $visite->{$user}->{$id}->{'duration'} = $time - $visite->{$user}->{$id}->{'started'} ;
133   - if ($visite->{$user}->{'last_referer'} eq $referer) {
134   - # same page/frame
135   - } else {
136   - # new frame/page
137   - $visite->{$user}->{$id}->{'page'}++;
138   - $visite->{$user}->{'last_referer'}=$referer;
139   - }
140   -
141   - }
142   -
143   - } else {# new visitor
  130 + # update duration
  131 + $visite->{$user}->{$id}->{'duration'} = $time - $visite->{$user}->{$id}->{'started'} ;
  132 + if ($visite->{$user}->{'last_referer'} eq $referer) {
  133 + # same page/frame
  134 + } else {
  135 + # new frame/page
  136 + $visite->{$user}->{$id}->{'page'}++;
  137 + $visite->{$user}->{'last_referer'}=$referer;
  138 + }
  139 + }
  140 + } else {# new visitor
144 141 $visit_tot ++;
145   - $visite->{$user}->{'id'}=1;
  142 + $visite->{$user}->{'id'}=1;
146 143 $id = 1;
147   - $visite->{$user}->{'last_visit'}=$time;
148   - $visite->{$user}->{'last_referer'}=$referer;
149   - $visite->{$user}->{$id}->{'started'}=$time;
  144 + $visite->{$user}->{'last_visit'}=$time;
  145 + $visite->{$user}->{'last_referer'}=$referer;
  146 + $visite->{$user}->{$id}->{'started'}=$time;
150 147 $visite->{$user}->{$id}->{'last_request'}=$time;
151   - $visite->{$user}->{$id}->{'hit'}=1;
152   - $visite->{$user}->{$id}->{'page'}=1;
153   - $visite->{$user}->{$id}->{'duration'}=0;
  148 + $visite->{$user}->{$id}->{'hit'}=1;
  149 + $visite->{$user}->{$id}->{'page'}=1;
  150 + $visite->{$user}->{$id}->{'duration'}=0;
154 151 $visite->{$user}->{$id}->{'tsunami'} = '<session name="'.$ip."-".$id.'" type="ts_http">'."\n";
155 152 $visite->{$user}->{$id}->{'tsunami'} .= "\t".'<request><http url="'.$url.'" version="'.$version.'" method="'.$method.'"></http></request>'."\n";
156   - }
157   - $total ++;
158   - } else {
159   -# print STDERR "$_\n";
160   - $bad ++;
161   - }
  153 + }
  154 + $total ++;
  155 + } else {
  156 +# print STDERR "$_\n";
  157 + $bad ++;
  158 + }
162 159 }
163 160 my $users_tot=scalar %{$visite};
164 161 my $page_tot=0;
@@ -185,36 +182,36 @@ print '<idx-tsunami loglevel="notice" dumptraffic="false" version="1.0">
185 182 ';
186 183 my $real_visit = 0;
187 184 foreach my $key (keys %$visite) {
188   - foreach my $id (1..$visite->{$key}->{'id'}) {
189   - my $page = $visite->{$key}->{$id}->{'page'};
190   - my $hit = $visite->{$key}->{$id}->{'hit'};
  185 + foreach my $id (1..$visite->{$key}->{'id'}) {
  186 + my $page = $visite->{$key}->{$id}->{'page'};
  187 + my $hit = $visite->{$key}->{$id}->{'hit'};
191 188 $real_visit ++ if $hit > $session_threshold;
192 189 }
193 190 }
194 191 foreach my $key (sort {$visite->{$a}->{'id'} cmp $visite->{$b}->{'id'}} keys %$visite) {
195   - my $tot_id = $visite->{$key}->{'id'};
196   - print STDERR "number of visit for $key is $tot_id\n" if $verbose;
197   - foreach my $id (1..$tot_id) {
198   - my $page = $visite->{$key}->{$id}->{'page'};
199   - my $hit = $visite->{$key}->{$id}->{'hit'};
200   - my $duration = $visite->{$key}->{$id}->{'duration'};
201   - if ($page < $max_pages and $duration < $max_duration) {
202   - $page_tot += $page;
203   - $hit_tot += $hit;
204   - print STDERR " page=$page hit=$hit duration=$duration\n" if $verbose;
205   - } else {
206   - $bad_visit++;
207   - $bad_pages +=$page;
  192 + my $tot_id = $visite->{$key}->{'id'};
  193 + print STDERR "number of visit for $key is $tot_id\n" if $verbose;
  194 + foreach my $id (1..$tot_id) {
  195 + my $page = $visite->{$key}->{$id}->{'page'};
  196 + my $hit = $visite->{$key}->{$id}->{'hit'};
  197 + my $duration = $visite->{$key}->{$id}->{'duration'};
  198 + if ($page < $max_pages and $duration < $max_duration) {
  199 + $page_tot += $page;
  200 + $hit_tot += $hit;
  201 + print STDERR " page=$page hit=$hit duration=$duration\n" if $verbose;
  202 + } else {
  203 + $bad_visit++;
  204 + $bad_pages +=$page;
  205 +
  206 + print STDERR "# page=$page hit=$hit duration=$duration\n" if $verbose;
208 207
209   - print STDERR "# page=$page hit=$hit duration=$duration\n" if $verbose;
210   -
211   - }
  208 + }
212 209 next unless $hit > $session_threshold;
213 210 my $pop=sprintf "%.3f",100/$real_visit;
214 211 my $tsunami = $visite->{$key}->{$id}->{'tsunami'};
215 212 $tsunami =~ s/\<session/<session popularity=\"$pop\"/;
216 213 print "$tsunami</session>\n";
217   - }
  214 + }
218 215 }
219 216 print '</idx-tsunami>';
220 217 if ($verbose) {
@@ -238,9 +235,9 @@ sub replace_entities {
238 235 }
239 236 sub usage {
240 237 print "log2tsunami.pl: create a config file for IDX-Tsunami from a Combined Log file\n\n";
241   - print "This script is part of IDX-TSUNAMI version $tagvsn,
  238 + print "This script is part of IDX-TSUNAMI version $tagvsn,
242 239 Copyright (C) 2004 Nicolas Niclausse\n\n";
243   - print "IDX-TSUNAMI comes with ABSOLUTELY NO WARRANTY; This is free software, and
  240 + print "IDX-TSUNAMI comes with ABSOLUTELY NO WARRANTY; This is free software, and
244 241 ou are welcome to redistribute it under certain conditions
245 242 type `log2tsunami.pl --version` for details.\n\n";
246 243
@@ -251,8 +248,8 @@ type `log2tsunami.pl --version` for details.\n\n";
251 248 "[--st <integer>] (session threshold : min number of requests (def=2))\n\t",
252 249 "[--max_duration <integer>] (maximum session duration in sec. (3600))\n\t",
253 250 "[--max_pages <integer>] (maximum number of pages winthin a session. (100))\n\t";
254   - exit;
255   - }
  251 + exit;
  252 + }
256 253
257 254 sub version {
258 255 print "this script is part of IDX-TSUNAMI version $tagvsn

0 comments on commit a085fb8

Please sign in to comment.
Something went wrong with that request. Please try again.