Commit a40a5f1c authored by Vincent Pelletier's avatar Vincent Pelletier

Compute hottest URLs instead of slowest.

Slowest page list is cluttered by temporary issues not representative of
service.
parent 78f68acb
...@@ -52,7 +52,6 @@ MONTH_VALUE_DICT = dict((y, x) for (x, y) in enumerate(('Jan', 'Feb', 'Mar', ...@@ -52,7 +52,6 @@ MONTH_VALUE_DICT = dict((y, x) for (x, y) in enumerate(('Jan', 'Feb', 'Mar',
US_PER_S = 10 ** 6 US_PER_S = 10 ** 6
N_SLOWEST = 20 N_SLOWEST = 20
N_SLOWEST_THRESHOLD = N_SLOWEST * 4
N_ERROR_URL = 10 N_ERROR_URL = 10
N_REFERRER_PER_ERROR_URL = 5 N_REFERRER_PER_ERROR_URL = 5
ITEMGETTER0 = itemgetter(0) ITEMGETTER0 = itemgetter(0)
...@@ -147,7 +146,7 @@ class GenericSiteStats(object): ...@@ -147,7 +146,7 @@ class GenericSiteStats(object):
self.status = defaultdict(partial(defaultdict, int)) self.status = defaultdict(partial(defaultdict, int))
if error_detail: if error_detail:
self.error_url_count = defaultdict(partial(defaultdict, list)) self.error_url_count = defaultdict(partial(defaultdict, list))
self.slowest_list = [(-1, None, None, None)] self.url_apdex = defaultdict(partial(APDEXStats, threshold))
self.apdex = defaultdict(partial(APDEXStats, threshold)) self.apdex = defaultdict(partial(APDEXStats, threshold))
def accumulate(self, match, url_match, date): def accumulate(self, match, url_match, date):
...@@ -157,23 +156,14 @@ class GenericSiteStats(object): ...@@ -157,23 +156,14 @@ class GenericSiteStats(object):
url = match.group('request') url = match.group('request')
else: else:
url = url_match.group('url') url = url_match.group('url')
if duration > self.slowest_list[0][0]: # XXX: can eat memory if there are many different urls
slowest_list = self.slowest_list self.url_apdex[url.split('?', 1)[0]].accumulate(match)
slowest_list.append((duration, match.group('timestamp'), url,
match.group('referer')))
if len(slowest_list) > N_SLOWEST_THRESHOLD:
self._housekeeping()
status = match.group('status') status = match.group('status')
self.status[status][date] += 1 self.status[status][date] += 1
if self.error_detail and statusIsError(status): if self.error_detail and statusIsError(status):
# XXX: can eat memory if there are many errors on many different urls # XXX: can eat memory if there are many errors on many different urls
self.error_url_count[status][url].append(match.group('referer')) self.error_url_count[status][url].append(match.group('referer'))
def _housekeeping(self):
slowest_list = self.slowest_list
slowest_list.sort(key=ITEMGETTER0)
slowest_list[:] = slowest_list[-N_SLOWEST:]
def getApdexData(self): def getApdexData(self):
apdex = APDEXStats(self.threshold) apdex = APDEXStats(self.threshold)
for data in self.apdex.itervalues(): for data in self.apdex.itervalues():
...@@ -184,7 +174,6 @@ class GenericSiteStats(object): ...@@ -184,7 +174,6 @@ class GenericSiteStats(object):
in sorted(self.apdex.iteritems(), key=ITEMGETTER0)] in sorted(self.apdex.iteritems(), key=ITEMGETTER0)]
def asHTML(self, stat_filter=lambda x: x): def asHTML(self, stat_filter=lambda x: x):
self._housekeeping()
result = [] result = []
append = result.append append = result.append
apdex = APDEXStats(self.threshold) apdex = APDEXStats(self.threshold)
...@@ -247,19 +236,14 @@ class GenericSiteStats(object): ...@@ -247,19 +236,14 @@ class GenericSiteStats(object):
)) ))
append('</tr>') append('</tr>')
append('</table>') append('</table>')
append('<h2>Slowest pages</h2><table class="stats"><tr>' append('<h2>Hottest pages</h2><table class="stats"><tr>')
'<th>duration (s)</th><th>date</th><th>url</th><th>referer</th></tr>') append(APDEX_TABLE_HEADERS)
for duration, timestamp, url, referer in reversed(self.slowest_list): append('<th>url</th></tr>')
if timestamp is None: for url, data in sorted(self.url_apdex.iteritems(), key=lambda x: x[1].getAverage() * x[1].hit,
continue reverse=True)[:N_SLOWEST]:
append('<tr><td class="%s">%.2f</td><td>%s</td>' append('<tr>')
'<td class="text">%s</td><td class="text">%s</td></tr>' % ( append(getApdexStatsAsHtml(data, self.threshold))
getClassForDuration(duration, self.threshold), append('<td class="text">%s</td></tr>' % escape(url))
float(duration) / US_PER_S,
escape(timestamp),
escape(url),
escape(referer),
))
append('</table>') append('</table>')
return '\n'.join(result) return '\n'.join(result)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment