From: Edita Kizinevic Date: Tue, 19 May 2020 12:10:24 +0000 (+0200) Subject: Add request time X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=93ac5a643bf7005ec991e71ebe0d72d018208b92;p=thirdparty%2FAWStats.git Add request time --- diff --git a/wwwroot/cgi-bin/awstats.model.conf b/wwwroot/cgi-bin/awstats.model.conf index d0108b29..c8c9a65a 100644 --- a/wwwroot/cgi-bin/awstats.model.conf +++ b/wwwroot/cgi-bin/awstats.model.conf @@ -93,6 +93,7 @@ LogType=W # %bytesd Size of document in bytes # %refererquot Referer page with format: "http://from.com/from.htm" # %referer Referer page with format: http://from.com/from.htm +# %rqtime Request time # %uabracket User agent with format: [Mozilla/4.0 (compatible, ...)] # %uaquot User agent with format: "Mozilla/4.0 (compatible, ...)" # %ua User agent with format: Mozilla/4.0_(compatible...) @@ -1054,6 +1055,10 @@ ShowFileTypesStats=HB # Default: 1, Possible column codes: None ShowFileSizesStats=0 +# Show request time chart +# Default: 0, Possible column codes: None +ShowRequestTimesStats=0 + # Show downloads chart. # Context: Web, Streaming, Ftp # Default: HB, Possible column codes: HB diff --git a/wwwroot/cgi-bin/awstats.pl b/wwwroot/cgi-bin/awstats.pl index 3a3d4c6f..d8fe8bee 100755 --- a/wwwroot/cgi-bin/awstats.pl +++ b/wwwroot/cgi-bin/awstats.pl @@ -84,7 +84,7 @@ use vars qw/ $TotalSearchEnginesPages $TotalSearchEnginesHits $TotalRefererPages $TotalRefererHits $TotalDifferentSearchEngines $TotalDifferentReferer $FrameName $Center $FileConfig $FileSuffix $Host $YearRequired $MonthRequired $DayRequired $HourRequired $QueryString $SiteConfig $StaticLinks $PageCode $PageDir $PerlParsingFormat $UserAgent - $pos_vh $pos_host $pos_logname $pos_date $pos_tz $pos_method $pos_url $pos_code $pos_size + $pos_vh $pos_host $pos_logname $pos_date $pos_tz $pos_method $pos_url $pos_code $pos_size $pos_time $pos_referer $pos_agent $pos_query $pos_gzipin $pos_gzipout $pos_compratio $pos_timetaken $pos_cluster $pos_emails $pos_emailr $pos_hostr @pos_extra /; @@ -187,7 +187,7 @@ use vars qw/ $NbOfLinesParsed $NbOfLinesDropped $NbOfLinesCorrupted $NbOfLinesComment $NbOfLinesBlank $NbOfOldLines $NbOfNewLines $NbOfLinesShowsteps $NewLinePhase $NbOfLinesForCorruptedLog $PurgeLogFile $ArchiveLogRecords $ShowDropped $ShowCorrupted $ShowUnknownOrigin $ShowDirectOrigin $ShowLinksToWhoIs - $ShowAuthenticatedUsers $ShowFileSizesStats $ShowScreenSizeStats $ShowSMTPErrorsStats + $ShowAuthenticatedUsers $ShowFileSizesStats $ShowRequestTimesStats $ShowScreenSizeStats $ShowSMTPErrorsStats $ShowEMailSenders $ShowEMailReceivers $ShowWormsStats $ShowClusterStats $IncludeInternalLinksInOriginSection $AuthenticatedUsersNotCaseSensitive @@ -224,6 +224,7 @@ use vars qw/ $ShowLinksToWhoIs, $ShowAuthenticatedUsers, $ShowFileSizesStats, + $ShowRequestTimesStats, $ShowScreenSizeStats, $ShowSMTPErrorsStats, $ShowEMailSenders, @@ -243,7 +244,8 @@ use vars qw/ ) = ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 ); use vars qw/ $DetailedReportsOnNewWindows @@ -373,6 +375,7 @@ use vars qw/ use vars qw/ @MiscListOrder %MiscListCalc %OSFamily %BrowsersFamily @SessionsRange %SessionsAverage + @TimeRange %TimeAverage %LangBrowserToLangAwstats %LangAWStatsToFlagAwstats %BrowsersSafariBuildToVersionHash @HostAliases @AllowAccessFromWebToFollowingAuthenticatedUsers @DefaultFile @SkipDNSLookupFor @@ -413,6 +416,12 @@ use vars qw/ '1h+', 3600 ); +@TimeRange = ('0-44', '44-100', '100-500', '500-1K', '1K-2K', '2K-5K', '5K+'); +%TimeAverage = ( + '0-44', 44, '44-100', 100, '100-500', 500, '500-1K', 1024, + '1K-2K', 2048, '2K-5K', 5120, '5K+', 5121 +); + # HTTP-Accept or Lang parameter => AWStats code to use for lang # ISO-639-1 or 2 or other => awstats-xx.txt where xx is ISO-639-1 %LangBrowserToLangAwstats = ( @@ -526,6 +535,7 @@ use vars qw/ %MonthPages %MonthHits %MonthBytes %MonthNotViewedPages %MonthNotViewedHits %MonthNotViewedBytes %_session %_browser_h %_browser_p + %_requesttime %_domener_p %_domener_h %_domener_k %_errors_h %_errors_k %_filetypes_h %_filetypes_k %_filetypes_gz_in %_filetypes_gz_out %_host_p %_host_h %_host_k %_host_l %_host_s %_host_u @@ -739,7 +749,13 @@ use vars qw/ @Message /; 'Konqueror versions', ',', 'Downloads', - 'Export CSV' + 'Export CSV', + 'Frequency[/s]', + 'Number of requests', + 'Period', + 's', + 'Request average frequency [/s]', + 'Request time' ); #------------------------------------------------------------------------------ @@ -1615,6 +1631,25 @@ sub Get_Filename{ return $temp; } +#------------------------------------------------------------------------------ +# Function: Return string of Request Time Range +# Parameters: $starttime $endtime +# Input: None +# Output: None +# Return: A string that identify the time range +#------------------------------------------------------------------------------ +sub GetRequestTimeRange { + my $rqtime = shift; + if ($Debug) { debug("GetRequestTimeRange $rqtime",4); } + if ($rqtime <= 44) { return $TimeRange[0]; } + if ($rqtime <= 100) { return $TimeRange[1]; } + if ($rqtime <= 500) { return $TimeRange[2]; } + if ($rqtime <= 1024) { return $TimeRange[3]; } + if ($rqtime <= 2048) { return $TimeRange[4]; } + if ($rqtime <= 5120) { return $TimeRange[5]; } + return $TimeRange[6]; +} + #------------------------------------------------------------------------------ # Function: Compare two browsers version # Parameters: $a @@ -3393,6 +3428,7 @@ sub Read_History_With_TmpUpdate { 'searchwords' => 25, 'keywords' => 26, 'errors' => 27, + 'requesttime' => 28, ); my $order = ( scalar keys %allsections ) + 1; @@ -3501,6 +3537,13 @@ sub Read_History_With_TmpUpdate { { $SectionsToLoad{'session'} = $order++; } + if ( $UpdateStats + || $MigrateStats + || ( $HTMLOutput{'main'} && $ShowRequestTimesStats ) + || $HTMLOutput{'requesttime'} ) + { + $SectionsToLoad{'requesttime'} = $order++; + } if ( $UpdateStats || $MigrateStats || ( $HTMLOutput{'main'} && $ShowPagesStats ) @@ -3847,6 +3890,52 @@ sub Read_History_With_TmpUpdate { next; } + # BEGIN_REQUESTTIME + if ( $field[0] eq 'BEGIN_REQUESTTIME' ) { + if ($Debug) { debug(" Begin of REQUESTTIME section"); } + $field[0] = ''; + my $count = 0; + my $countloaded = 0; + do { + if ( $field[0] ) { + $count++; + if ( $SectionsToLoad{'requesttime'} ) { + $countloaded++; + if ( $field[1] ) { + $_requesttime{ $field[0] } += $field[1]; + } } + } + $_ = ; + chomp $_; + s/\r//; + @field = + split( /\s+/, + ( $readxml ? CleanFromTags($_) : $_) ); + $countlines++; + } until ( $field[0] eq 'END_REQUESTTIME' + || $field[0] eq "${xmleb}END_REQUESTTIME" + || !$_ ); + if ( $field[0] ne 'END_REQUESTTIME' + && $field[0] ne "${xmleb}END_REQUESTTIME") + { + error( +"History file \"$filetoread\" is corrupted (End of section REQUESTTIME not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).", + "", "", 1 + ); + } + if ($Debug) { + debug( +" End of _REQUESTTIME section ($count entries, $countloaded loaded)" + ); + } + delete $SectionsToLoad{'filesize'}; + if ( !scalar %SectionsToLoad ) { + debug(" Stop reading history file. Got all we need."); + last; + } + next; + } + # BEGIN_MISC if ( $field[0] eq 'BEGIN_MISC' ) { if ($Debug) { debug(" Begin of MISC section"); } @@ -6340,6 +6429,9 @@ sub Save_History { print HISTORYTMP "${xmlrb}POS_SESSION${xmlrs}"; $PosInFile{"session"} = tell HISTORYTMP; print HISTORYTMP "$spacebar${xmlre}\n"; + print HISTORYTMP "${xmlrb}POS_REQUESTTIME${xmlrs}"; + $PosInFile{"requesttime"} = tell HISTORYTMP; + print HISTORYTMP "$spacebar${xmlre}\n"; print HISTORYTMP "${xmlrb}POS_SIDER${xmlrs}"; $PosInFile{"sider"} = tell HISTORYTMP; print HISTORYTMP "$spacebar${xmlre}\n"; @@ -6870,6 +6962,24 @@ sub Save_History { } print HISTORYTMP "${xmleb}END_SESSION${xmlee}\n"; } + if ( $sectiontosave eq 'requesttime' ) { + print HISTORYTMP "\n"; + if ($xml) { + print HISTORYTMP "
\n"; + } + print HISTORYTMP "# Request Time Range - Request Time Frequency\n"; + $ValueInFile{$sectiontosave} = tell HISTORYTMP; + print HISTORYTMP "${xmlbb}BEGIN_REQUESTTIME${xmlbs}" + . ( scalar keys %_requesttime ) + . "${xmlbe}\n"; + foreach ( keys %_requesttime ) { + print HISTORYTMP "${xmlrb}$_${xmlrs}" + . int( $_requesttime{$_} ) + . "${xmlre}\n"; + } + print HISTORYTMP "${xmleb}END_REQUESTTIME${xmlee}\n"; + + } if ( $sectiontosave eq 'sider' ) { # This section must be saved after VISITOR section is read print HISTORYTMP "\n"; @@ -7746,6 +7856,7 @@ sub Init_HashArray { # Reset all hash arrays with name beginning by _ %_session = %_browser_h = %_browser_p = (); + %_requesttime = (); %_domener_p = %_domener_h = %_domener_k = %_errors_h = %_errors_k = (); %_filetypes_h = %_filetypes_k = %_filetypes_gz_in = %_filetypes_gz_out = (); %_host_p = %_host_h = %_host_k = %_host_l = %_host_s = %_host_u = (); @@ -8930,7 +9041,7 @@ sub HTMLShowURLInfo { sub DefinePerlParsingFormat { my $LogFormat = shift; $pos_vh = $pos_host = $pos_logname = $pos_date = $pos_tz = $pos_method = - $pos_url = $pos_code = $pos_size = -1; + $pos_url = $pos_code = $pos_size = $pos_time = -1; $pos_referer = $pos_agent = $pos_query = $pos_gzipin = $pos_gzipout = $pos_compratio = -1; $pos_cluster = $pos_emails = $pos_emailr = $pos_hostr = -1; @@ -9289,6 +9400,12 @@ sub DefinePerlParsingFormat { push @fieldlib, 'size'; $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)"; } + elsif ( $f =~ /%rqtime$/ ) { + $pos_time = $i; + $i++; + push @fieldlib, 'requesttime'; + $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)"; + } elsif ( $f =~ /%refererquot$/ ) { $pos_referer = $i; $i++; @@ -10301,6 +10418,12 @@ sub HTMLMenu{ "$Message[117]"; print( $frame? "\n" : "   " ); } + if ($ShowRequestTimesStats) { + print( $frame? "" : "" ); + print +"$Message[185]"; + print ($frame? "\n" : "   " ); + } if ($ShowFileTypesStats && $LevelForFileTypesDetection > 0) { print( $frame? "" : "" ); print @@ -10772,6 +10895,85 @@ sub HTMLMainFileType{ &tab_end(); } +#------------------------------------------------------------------------------ +# Function: Prints Request Time table +# Parameters: _ +# Input: _ +# Output: HTML +# Return: - +#------------------------------------------------------------------------------ +sub HTMLMainRequestTime{ + if ($Debug) { debug("ShowRequestTimesStats", 2); } + my $FirstTime = 0; + my $LastTime = 0; + foreach my $key ( keys %FirstTime ) { + my $keyqualified = 0; + if ( $MonthRequired eq 'all' ) { $keyqualified = 1; } + if ( $key =~ /^$YearRequired$MonthRequired/ ) { $keyqualified = 1; } + if ($keyqualified) { + if ( $FirstTime{$key} + && ( $FirstTime == 0 || $FirstTime > $FirstTime{$key} ) ) + { + $FirstTime = $FirstTime{$key}; + } + if ( $LastTime < ( $LastTime{$key} || 0 ) ) { + $LastTime = $LastTime{$key}; + } + } + } + + my $inicio = 0; + my $fim = 0; + if ($FirstTime =~ /$regdate/o) { $inicio = Time::Local::timelocal($6,$5,$4,$3,$2-1,$1); } + if ($LastTime =~ /$regdate/o) { $fim = Time::Local::timelocal($6,$5,$4,$3,$2-1,$1); } + my $periodo = $fim - $inicio; + my $number_of_requests = 0; + my $request_frequency_average = 0; + foreach my $key (@TimeRange) { + $number_of_requests += $_requesttime{$key}; + } + if ($periodo) { $request_frequency_average = $number_of_requests / $periodo;} + else { $request_frequency_average = 0}; + print "$Center 
\n"; + my $title = "$Message[185]"; + &tab_head($title, 19, 0, 'requesttimes'); + my $Totals = 0; + my $average_s = 0; + foreach (@TimeRange) { + $average_s += ($_requesttime{$_} || 0) * $TimeAverage{$_}; + $Totals += $_requesttime{$_} || 0; + } + if ($Totals) { $average_s = int($average_s / $Totals); } + else { $average_s = '?'; } + print "$Message[181]: $number_of_requests - $Message[182]: $periodo $Message[183] - $Message[184]: ".sprintf ("%.6f",$request_frequency_average)."$Message[180]$Message[57]$Message[15]\n"; + my $total_s = 0; + my $count = 0; + foreach my $key (@TimeRange) { + my $p = 0; + my $f = 0; + if ($Totals) { $p = int($_requesttime{$key} / $Totals * 1000) / 10; } + if ($periodo) { $f = $_requesttime{$key} / $periodo; } + $total_s += $_requesttime{$key} || 0; + print "$key"; + print "".($_requesttime{$key} ? sprintf("%.5f",$f) : " ").""; + print "".($_requesttime{$key} ? $_requesttime{$key} : " ").""; + print "".($_requesttime{$key} ? "$p %" : " ").""; + print "\n"; + $count++; + } + my $rest_s = $TotalVisits - $total_s; + if ($rest_s > 0) { + my $p = 0; + if ($TotalVisits) { $p = int($rest_s / $TotalVisits * 1000) / 10; } + print "$Message[0]"; + print "$rest_s"; + print "".($rest_s?"$p %":" ").""; + print "\n"; + } + + &tab_end(); +} + #------------------------------------------------------------------------------ # Function: Prints the Browser Detail frame or static page # Parameters: _ @@ -20243,6 +20445,13 @@ s/^(cache|related):[^\+]+// int( $field[$pos_size] );} #Count accesses for page (kb) } + # Check request time frequency + #----------------------------- + if ( $pos_time >= 0 ) + { + $_requesttime{GetRequestTimeRange(int($field[$pos_time]))}++; + } + # Analyze: Extra #--------------- foreach my $extranum ( 1 .. @ExtraName - 1 ) { @@ -21347,6 +21556,12 @@ if ( scalar keys %HTMLOutput ) { if ($ShowFileSizesStats) { # TODO } + + # BY REQUEST TIME + #------------------------- + if ($ShowRequestTimesStats) { + &HTMLMainRequestTime(); + } # BY DOWNLOADS #------------------------- diff --git a/wwwroot/cgi-bin/lang/awstats-en.txt b/wwwroot/cgi-bin/lang/awstats-en.txt index f8f4d562..27abc620 100644 --- a/wwwroot/cgi-bin/lang/awstats-en.txt +++ b/wwwroot/cgi-bin/lang/awstats-en.txt @@ -180,4 +180,10 @@ message175=Chrome versions message176=Konqueror versions message177=, message178=Downloads -message179=TB \ No newline at end of file +message179=TB +message180=Frequency[/s] +message181=Number of requests +message182=Period +message183=s +message184=Request average frequency [/s] +message185=Request time