Skip to content

Instantly share code, notes, and snippets.

@eristoddle
Created May 29, 2013 17:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eristoddle/5672037 to your computer and use it in GitHub Desktop.
Save eristoddle/5672037 to your computer and use it in GitHub Desktop.
Patch file for awstats to process response time
Index: wwwroot/cgi-bin/awstats.pl
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- wwwroot/cgi-bin/awstats.pl (revision )
+++ wwwroot/cgi-bin/awstats.pl (revision )
@@ -80,7 +80,7 @@
$TotalUnique $TotalVisits $TotalHostsKnown $TotalHostsUnknown
$TotalPages $TotalHits $TotalBytes $TotalHitsErrors
$TotalNotViewedPages $TotalNotViewedHits $TotalNotViewedBytes
- $TotalEntries $TotalExits $TotalBytesPages $TotalDifferentPages
+ $TotalEntries $TotalExits $TotalBytesPages $TotalTimeTaken $TotalDifferentPages
$TotalKeyphrases $TotalKeywords $TotalDifferentKeyphrases $TotalDifferentKeywords
$TotalSearchEnginesPages $TotalSearchEnginesHits $TotalRefererPages $TotalRefererHits $TotalDifferentSearchEngines $TotalDifferentReferer
$FrameName $Center $FileConfig $FileSuffix $Host $YearRequired $MonthRequired $DayRequired $HourRequired
@@ -102,7 +102,7 @@
$TotalUnique = $TotalVisits = $TotalHostsKnown = $TotalHostsUnknown = 0;
$TotalPages = $TotalHits = $TotalBytes = $TotalHitsErrors = 0;
$TotalNotViewedPages = $TotalNotViewedHits = $TotalNotViewedBytes = 0;
-$TotalEntries = $TotalExits = $TotalBytesPages = $TotalDifferentPages = 0;
+$TotalEntries = $TotalExits = $TotalBytesPages = $TotalTimeTaken = $TotalDifferentPages = 0;
$TotalKeyphrases = $TotalKeywords = $TotalDifferentKeyphrases = 0;
$TotalDifferentKeywords = 0;
$TotalSearchEnginesPages = $TotalSearchEnginesHits = $TotalRefererPages = 0;
@@ -176,8 +176,9 @@
'vh' => 'vh.png',
'hh' => 'hh.png',
'vk' => 'vk.png',
- 'hk' => 'hk.png'
+ 'hk' => 'hk.png',
+ 'ht' => 'ht.png'
-);
+ );
$BuildReportFormat = 'html';
$BuildHistoryFormat = 'text';
$ExtraTrackedRowsLimit = 500;
@@ -336,7 +337,7 @@
$color_Background $color_TableBG $color_TableBGRowTitle
$color_TableBGTitle $color_TableBorder $color_TableRowTitle $color_TableTitle
$color_text $color_textpercent $color_titletext $color_weekend $color_link $color_hover $color_other
- $color_h $color_k $color_p $color_e $color_x $color_s $color_u $color_v
+ $color_h $color_k $color_p $color_e $color_x $color_s $color_u $color_v $color_t
/;
(
$color_Background, $color_TableBG, $color_TableBGRowTitle,
@@ -346,11 +347,11 @@
$color_hover, $color_other, $color_h,
$color_k, $color_p, $color_e,
$color_x, $color_s, $color_u,
- $color_v
+ $color_v, $color_t
)
= (
'', '', '', '', '', '', '', '', '', '', '', '',
- '', '', '', '', '', '', '', '', '', ''
+ '', '', '', '', '', '', '', '', '', '', ''
);
# ---------- Init arrays --------
@@ -533,7 +534,7 @@
%_worm_h %_worm_k %_worm_l %_login_h %_login_p %_login_k %_login_l %_screensize_h
%_misc_p %_misc_h %_misc_k
%_cluster_p %_cluster_h %_cluster_k
- %_se_referrals_p %_se_referrals_h %_sider404_h %_referer404_h %_url_p %_url_k %_url_e %_url_x
+ %_se_referrals_p %_se_referrals_h %_sider404_h %_referer404_h %_url_p %_url_k %_url_e %_url_x %_url_t
%_downloads
%_unknownreferer_l %_unknownrefererbrowser_l
%_emails_h %_emails_k %_emails_l %_emailr_h %_emailr_k %_emailr_l
@@ -2841,6 +2842,8 @@
if ( $color_h !~ /^[0-9|A-H]+$/i ) { $color_h = '66EEFF'; }
$color_k =~ s/#//g;
if ( $color_k !~ /^[0-9|A-H]+$/i ) { $color_k = '2EA495'; }
+ $color_t =~ s/#//g;
+ if ( $color_t !~ /^[0-9|A-H]+$/i ) { $color_t = '8495AC'; }
$color_s =~ s/#//g;
if ( $color_s !~ /^[0-9|A-H]+$/i ) { $color_s = '8888DD'; }
$color_e =~ s/#//g;
@@ -5202,6 +5205,7 @@
$TotalBytesPages += ( $field[2] || 0 );
$TotalEntries += ( $field[3] || 0 );
$TotalExits += ( $field[4] || 0 );
+ $TotalTimeTaken += ( $field[5] || 0)
}
if ($loadrecord) {
if ( $field[1] ) {
@@ -5216,6 +5220,8 @@
if ( $field[4] ) {
$_url_x{ $field[0] } += $field[4];
}
+ if ( $field[5] ) { $_url_t{ $field[0] } += $field[5];
+ }
$countloaded++;
}
}
@@ -5248,8 +5254,8 @@
# WE DO NOT SAVE SECTION NOW BECAUSE VALUES CAN BE CHANGED AFTER READING VISITOR
#if ($SectionsToSave{'sider'}) {
# Save_History('sider',$year,$month,$date); delete $SectionsToSave{'sider'};
-# if ($withpurge) { %_url_p=(); %_url_k=(); %_url_e=(); %_url_x=(); }
+#if ($withpurge) { %_url_p=(); %_url_k=(); %_url_e=(); %_url_x=(); %_url_t=(); }
-#}
+ #}
if ( !scalar %SectionsToLoad ) {
debug(" Stop reading history file. Got all we need.");
last;
@@ -6603,7 +6609,7 @@
print HISTORYTMP
"<section id='$sectiontosave'><sortfor>$MaxNbOf{'LoginShown'}</sortfor><comment>\n";
}
- print HISTORYTMP "# Login - Pages - Hits - Bandwidth - Last visit\n";
+ print HISTORYTMP "# URL - Pages - Bandwidth - Entry - Exit - Timetaken\n";
print HISTORYTMP
"# The $MaxNbOf{'LoginShown'} first Pages must be first (order not required for others)\n";
$ValueInFile{$sectiontosave} = tell HISTORYTMP;
@@ -6817,7 +6823,7 @@
print HISTORYTMP
"<section id='$sectiontosave'><sortfor>$MaxNbOf{'PageShown'}</sortfor><comment>\n";
}
- print HISTORYTMP "# URL - Pages - Bandwidth - Entry - Exit\n";
+ print HISTORYTMP "# URL - Pages - Bandwidth - Entry - Exit - Timetaken\n";
print HISTORYTMP
"# The $MaxNbOf{'PageShown'} first Pages must be first (order not required for others)\n";
$ValueInFile{$sectiontosave} = tell HISTORYTMP;
@@ -6844,6 +6850,8 @@
. int( $_url_e{$_} || 0 )
. "${xmlrs}"
. int( $_url_x{$_} || 0 )
+ . "${xmlrs}"
+ . ( $_url_t{$_} || 0 )
. "${xmlre}\n";
}
foreach ( keys %_url_p ) {
@@ -6861,6 +6869,8 @@
. int( $_url_e{$_} || 0 )
. "${xmlrs}"
. int( $_url_x{$_} || 0 )
+ . "${xmlrs}"
+ . ( $_url_t{$_} || 0 )
. "${xmlre}\n";
}
print HISTORYTMP "${xmleb}END_SIDER${xmlee}\n";
@@ -7691,7 +7701,7 @@
%_misc_p = %_misc_h = %_misc_k = ();
%_cluster_p = %_cluster_h = %_cluster_k = ();
%_se_referrals_p = %_se_referrals_h = %_sider404_h = %_referer404_h =
- %_url_p = %_url_k = %_url_e = %_url_x = ();
+ %_url_p = %_url_k = %_url_e = %_url_x = %_url_t = ();
%_downloads = ();
%_unknownreferer_l = %_unknownrefererbrowser_l = ();
%_emails_h = %_emails_k = %_emails_l = %_emailr_h = %_emailr_k =
@@ -8024,6 +8034,18 @@
}
#------------------------------------------------------------------------------
+# Function: Format value in seconds in a string (s)
+# Parameters: interval (float value)
+# Input: None
+# Output: None
+# Return: "X.YZWs" or "X.Y KB" or "x Bytes" or "0"
+#------------------------------------------------------------------------------
+sub Format_TimeInterval {
+ my $interval = shift || 0;
+ return sprintf( "%.3f", $interval ) . "s";
+}
+
+#------------------------------------------------------------------------------
# Function: Format a number with commas or any other separator
# CL: courtesy of http://www.perlmonks.org/?node_id=2145
# Parameters: number
@@ -11903,6 +11925,7 @@
my $total_e = 0;
my $total_k = 0;
my $total_x = 0;
+ my $total_t = 0;
# Call to plugins' function ShowPagesFilter
foreach
my $pluginname ( keys %{ $PluginsLoaded{'ShowPagesFilter'} } )
@@ -11959,6 +11982,10 @@
print
"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[106]</th>";
}
+ if ( $ShowPagesStats =~ /T/i ) {
+ print
+ "<th class=\"datasize\" bgcolor=\"#$color_t\" width=\"80\">Time Taken (Avg.)</th>";
+ }
if ( $ShowPagesStats =~ /E/i ) {
print
"<th bgcolor=\"#$color_e\" width=\"80\">$Message[104]</th>";
@@ -11995,12 +12022,16 @@
}
my $max_p = 1;
my $max_k = 1;
+ my $max_t = -1;
foreach my $key (@keylist) {
if ( $_url_p{$key} > $max_p ) { $max_p = $_url_p{$key}; }
if ( $_url_k{$key} / ( $_url_p{$key} || 1 ) > $max_k ) {
$max_k = $_url_k{$key} / ( $_url_p{$key} || 1 );
}
+ if ( $_url_t{$key} / ( $_url_p{$key} || 1 ) > $max_t ) {
+ $max_t = $_url_t{$key} / ( $_url_p{$key} || 1 );
- }
+ }
+ }
foreach my $key (@keylist) {
print "<tr><td class=\"aws\">";
&HTMLShowURLInfo($key);
@@ -12009,6 +12040,7 @@
my $bredde_e = 0;
my $bredde_x = 0;
my $bredde_k = 0;
+ my $bredde_t = 0;
if ( $max_p > 0 ) {
$bredde_p =
int( $BarWidth * ( $_url_p{$key} || 0 ) / $max_p ) + 1;
@@ -12031,6 +12063,13 @@
$max_k ) + 1;
}
if ( ( $bredde_k == 1 ) && $_url_k{$key} ) { $bredde_k = 2; }
+ if ( $max_t > 0 ) {
+ $bredde_t =
+ int( $BarWidth *
+ ( ( $_url_t{$key} || 0 ) / ( $_url_p{$key} || 1 ) ) /
+ $max_t ) + 1;
+ }
+ if ( ( $bredde_t <= 1 ) && $_url_t{$key} ) { $bredde_t = 2; }
if ( $ShowPagesStats =~ /P/i ) {
print "<td>".Format_Number($_url_p{$key})."</td>";
}
@@ -12045,6 +12084,17 @@
)
. "</td>";
}
+ if ( $ShowPagesStats =~ /T/i ) {
+ print "<td>"
+ . (
+ $_url_t{$key}
+ ? Format_TimeInterval(
+ $_url_t{$key} / ( $_url_p{$key} || 1 )
+ )
+ : "&nbsp;"
+ )
+ . "</td>";
+ }
if ( $ShowPagesStats =~ /E/i ) {
print "<td>"
. ( $_url_e{$key} ? Format_Number($_url_e{$key}) : "&nbsp;" ) . "</td>";
@@ -12075,6 +12125,10 @@
print
"<img src=\"$DirIcons\/other\/$BarPng{'hk'}\" width=\"$bredde_k\" height=\"4\" /><br />";
}
+ if ( $ShowPagesStats =~ /T/i ) {
+ print
+ "<img src=\"$DirIcons\/other\/$BarPng{'ht'}\" width=\"$bredde_t\" height=\"4\" /><br />";
+ }
if ( $ShowPagesStats =~ /E/i ) {
print
"<img src=\"$DirIcons\/other\/$BarPng{'he'}\" width=\"$bredde_e\" height=\"4\" /><br />";
@@ -12088,11 +12142,12 @@
$total_e += $_url_e{$key};
$total_x += $_url_x{$key};
$total_k += $_url_k{$key};
+ $total_t += $_url_t{$key};
$count++;
}
if ($Debug) {
debug(
-"Total real / shown : $TotalPages / $total_p - $TotalEntries / $total_e - $TotalExits / $total_x - $TotalBytesPages / $total_k",
+"Total real / shown : $TotalPages / $total_p - $TotalEntries / $total_e - $TotalExits / $total_x - $TotalBytesPages / $total_k - $TotalTimeTaken / $total_t",
2
);
}
@@ -12100,7 +12155,8 @@
my $rest_k = $TotalBytesPages - $total_k;
my $rest_e = $TotalEntries - $total_e;
my $rest_x = $TotalExits - $total_x;
- if ( $rest_p > 0 || $rest_e > 0 || $rest_k > 0 ) {
+ my $rest_t = $TotalTimeTaken - $total_t;
+ if ( $rest_p > 0 || $rest_e > 0 || $rest_k > 0 || $rest_t > 0 ) {
print
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
if ( $ShowPagesStats =~ /P/i ) {
@@ -12115,6 +12171,15 @@
)
. "</td>";
}
+ if ( $ShowPagesStats =~ /T/i ) {
+ print "<td>"
+ . (
+ $rest_t
+ ? Format_TimeInterval( $rest_t / ( $rest_p || 1 ) )
+ : "&nbsp;"
+ )
+ . "</td>";
+ }
if ( $ShowPagesStats =~ /E/i ) {
print "<td>" . ( $rest_e ? Format_Number($rest_e) : "&nbsp;" ) . "</td>";
}
@@ -15336,6 +15401,10 @@
print
"<th bgcolor=\"#$color_k\" width=\"80\">$Message[106]</th>";
}
+ if ( $ShowPagesStats =~ /T/i ) {
+ print
+ "<th bgcolor=\"#$color_t\" width=\"80\">Time Taken (Avg.)</th>";
+ }
if ( $ShowPagesStats =~ /E/i ) {
print
"<th bgcolor=\"#$color_e\" width=\"80\">$Message[104]</th>";
@@ -15357,8 +15426,10 @@
}
print "<th>&nbsp;</th></tr>\n";
my $total_p = my $total_e = my $total_x = my $total_k = 0;
+ my $total_p = my $total_e = my $total_x = my $total_k = my $total_t = 0;
my $max_p = 1;
my $max_k = 1;
+ my $max_t = -1;
my $count = 0;
&BuildKeyList( $MaxNbOf{'PageShown'}, $MinHit{'File'}, \%_url_p,
\%_url_p );
@@ -15367,7 +15438,10 @@
if ( $_url_k{$key} / ( $_url_p{$key} || 1 ) > $max_k ) {
$max_k = $_url_k{$key} / ( $_url_p{$key} || 1 );
}
+ if ( $_url_t{$key} / ( $_url_p{$key} || 1 ) > $max_t ) {
+ $max_t = $_url_t{$key} / ( $_url_p{$key} || 1 );
- }
+ }
+ }
foreach my $key (@keylist) {
print "<tr><td class=\"aws\">";
&HTMLShowURLInfo($key);
@@ -15376,6 +15450,7 @@
my $bredde_e = 0;
my $bredde_x = 0;
my $bredde_k = 0;
+ my $bredde_t = 0;
if ( $max_p > 0 ) {
$bredde_p =
int( $BarWidth * ( $_url_p{$key} || 0 ) / $max_p ) + 1;
@@ -15398,6 +15473,13 @@
$max_k ) + 1;
}
if ( ( $bredde_k == 1 ) && $_url_k{$key} ) { $bredde_k = 2; }
+ if ( $max_t > 0 ) {
+ $bredde_t =
+ int( $BarWidth *
+ ( ( $_url_t{$key} || 0 ) / ( $_url_p{$key} || 1 ) ) /
+ $max_t ) + 1;
+ }
+ if ( ( $bredde_t <= 1 ) && $_url_t{$key} ) { $bredde_t = 2; }
if ( $ShowPagesStats =~ /P/i && $LogType ne 'F' ) {
print "<td>".Format_Number($_url_p{$key})."</td>";
}
@@ -15415,6 +15497,15 @@
)
. "</td>";
}
+ if ( $ShowPagesStats =~ /T/i ) {
+ print "<td>"
+ . (
+ $_url_t{$key}
+ ? Format_TimeInterval($_url_t{$key} / ( $_url_p{$key} || 1 ))
+ : "&nbsp;"
+ )
+ . "</td>";
+ }
if ( $ShowPagesStats =~ /E/i ) {
print "<td>"
. ( $_url_e{$key} ? Format_Number($_url_e{$key}) : "&nbsp;" ) . "</td>";
@@ -15453,6 +15544,12 @@
. AltTitle("")
. " /><br />";
}
+ if ( $ShowPagesStats =~ /T/i ) {
+ print
+"<img src=\"$DirIcons\/other\/$BarPng{'ht'}\" width=\"$bredde_t\" height=\"4\""
+ . AltTitle("")
+ . " /><br />";
+ }
if ( $ShowPagesStats =~ /E/i ) {
print
"<img src=\"$DirIcons\/other\/$BarPng{'he'}\" width=\"$bredde_e\" height=\"4\""
@@ -15469,13 +15566,15 @@
$total_e += $_url_e{$key} || 0;
$total_x += $_url_x{$key} || 0;
$total_k += $_url_k{$key} || 0;
+ $total_t += $_url_t{$key} || 0;
$count++;
}
my $rest_p = $TotalPages - $total_p;
my $rest_e = $TotalEntries - $total_e;
my $rest_x = $TotalExits - $total_x;
my $rest_k = $TotalBytesPages - $total_k;
- if ( $rest_p > 0 || $rest_k > 0 || $rest_e > 0 || $rest_x > 0 )
+ my $rest_t = $TotalTimeTaken - $total_t;
+ if ( $rest_p > 0 || $rest_k > 0 || $rest_e > 0 || $rest_x > 0 || $rest_t > 0 )
{ # All other urls
print
"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
@@ -15494,6 +15593,15 @@
)
. "</td>";
}
+ if ( $ShowPagesStats =~ /T/i ) {
+ print "<td>"
+ . (
+ $rest_t
+ ? Format_TimeInterval( $rest_t / ( $rest_p || 1 ) )
+ : "&nbsp;"
+ )
+ . "</td>";
+ }
if ( $ShowPagesStats =~ /E/i ) {
print "<td>" . ( $rest_e ? Format_Number($rest_e) : "&nbsp;" ) . "</td>";
}
@@ -18949,7 +19057,7 @@
}
}
- # Analyze: Date - Hour - Pages - Hits - Kilo
+ # Analyze: Date - Hour - Pages - Hits - Kilo - TimeTaken
#-------------------------------------------
if ($PageBool) {
@@ -18969,6 +19077,9 @@
if ( $field[$pos_size] ne '-' && $pos_size>0) {
$_url_k{ $field[$pos_url] } += int( $field[$pos_size] );
}
+ if ( $pos_timetaken > 0 && $field[$pos_timetaken] ne '-' ) {
+ $_url_t{ $field[$pos_url] } += (0.0 + $field[$pos_timetaken]);
+ }
$_time_p[$hourrecord]++; #Count accesses for hour (page)
# TODO Use an id for hash key of url
# $_url_t{$_url_id}
@@ -20253,7 +20364,9 @@
. " _url_e:"
. ( scalar keys %_url_e )
. " _url_x:"
- . ( scalar keys %_url_x ) . "\n";
+ . ( scalar keys %_url_x )
+ . " _url_t:"
+ . ( scalar keys %_url_t ) . "\n";
print " _waithost_e:"
. ( scalar keys %_waithost_e )
. " _waithost_l:"
@@ -20644,7 +20757,12 @@
# TotalBytesPages (if not already specifically counted, we init it from _url_k hash table)
if ( !$TotalBytesPages ) {
foreach ( keys %_url_k ) { $TotalBytesPages += $_url_k{$_}; }
+ }
+
+# TotalTimeTaken (if not already specifically counted, we init it from _url_t hash table)
+ if ( !$TotalTimeTaken ) {
+ foreach ( keys %_url_t ) { $TotalTimeTaken += $_url_t{$_}; }
- }
+ }
# TotalKeyphrases (if not already specifically counted, we init it from _keyphrases hash table)
if ( !$TotalKeyphrases ) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment