Commit a7134ffa authored by Arnaud Fontaine's avatar Arnaud Fontaine Committed by Vincent Pelletier

apachedex: Add ``--n-hottest-pages'' command line parameter.

Allow to define how many pages will be displayed in 'Hottest pages' section.
parent 0ba22c47
...@@ -116,7 +116,7 @@ MONTH_VALUE_DICT = dict((y, x) for (x, y) in enumerate(('Jan', 'Feb', 'Mar', ...@@ -116,7 +116,7 @@ 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_HOTTEST_PAGES_DEFAULT = 20
N_ERROR_URL = 10 N_ERROR_URL = 10
N_REFERRER_PER_ERROR_URL = 5 N_REFERRER_PER_ERROR_URL = 5
N_USER_AGENT = 20 N_USER_AGENT = 20
...@@ -411,6 +411,7 @@ class GenericSiteStats(object): ...@@ -411,6 +411,7 @@ class GenericSiteStats(object):
x_min=None, x_max=None, x_min=None, x_max=None,
apdex_y_min=None, hit_y_min=None, hit_y_max=None, apdex_y_min=None, hit_y_min=None, hit_y_max=None,
apdex_y_scale=None, hit_y_scale=None, apdex_y_scale=None, hit_y_scale=None,
n_hottest_pages=N_HOTTEST_PAGES_DEFAULT,
): ):
result = [] result = []
append = result.append append = result.append
...@@ -425,7 +426,7 @@ class GenericSiteStats(object): ...@@ -425,7 +426,7 @@ class GenericSiteStats(object):
append(APDEXStats.asHTMLHeader()) append(APDEXStats.asHTMLHeader())
append('<th>url</th></tr>') append('<th>url</th></tr>')
for url, data in sorted(self.url_apdex.iteritems(), key=lambda x: x[1].getAverage() * x[1].hit, for url, data in sorted(self.url_apdex.iteritems(), key=lambda x: x[1].getAverage() * x[1].hit,
reverse=True)[:N_SLOWEST]: reverse=True)[:n_hottest_pages]:
append('<tr>') append('<tr>')
append(data.asHTML(self.threshold)) append(data.asHTML(self.threshold))
append('<td class="text">%s</td></tr>' % escape(url)) append('<td class="text">%s</td></tr>' % escape(url))
...@@ -625,6 +626,7 @@ class ERP5SiteStats(GenericSiteStats): ...@@ -625,6 +626,7 @@ class ERP5SiteStats(GenericSiteStats):
encoding, stat_filter=lambda x: x, x_min=None, x_max=None, encoding, stat_filter=lambda x: x, x_min=None, x_max=None,
apdex_y_min=None, hit_y_min=None, hit_y_max=None, apdex_y_min=None, hit_y_min=None, hit_y_max=None,
apdex_y_scale=None, hit_y_scale=None, apdex_y_scale=None, hit_y_scale=None,
n_hottest_pages=N_HOTTEST_PAGES_DEFAULT,
): ):
result = [] result = []
append = result.append append = result.append
...@@ -743,6 +745,7 @@ class ERP5SiteStats(GenericSiteStats): ...@@ -743,6 +745,7 @@ class ERP5SiteStats(GenericSiteStats):
apdex_y_min=apdex_y_min, hit_y_min=hit_y_min, hit_y_max=hit_y_max, apdex_y_min=apdex_y_min, hit_y_min=hit_y_min, hit_y_max=hit_y_max,
apdex_y_scale=apdex_y_scale, apdex_y_scale=apdex_y_scale,
hit_y_scale=hit_y_scale, hit_y_scale=hit_y_scale,
n_hottest_pages=n_hottest_pages,
)) ))
return '\n'.join(result) return '\n'.join(result)
...@@ -1151,6 +1154,7 @@ def asHTML(out, encoding, per_site, args, default_site, period_parameter_dict, ...@@ -1151,6 +1154,7 @@ def asHTML(out, encoding, per_site, args, default_site, period_parameter_dict,
for hit_date, hit in sorted(hit_per_day.iteritems(), key=ITEMGETTER0): for hit_date, hit in sorted(hit_per_day.iteritems(), key=ITEMGETTER0):
out.write('<tr><td>%s</td><td>%s</td></tr>' % (hit_date, hit)) out.write('<tr><td>%s</td><td>%s</td></tr>' % (hit_date, hit))
out.write('</table>') out.write('</table>')
n_hottest_pages = args.n_hottest_pages
for i, (site_id, data) in site_list: for i, (site_id, data) in site_list:
out.write('<h1 id="%s" title="%s">%s</h1>' % (i, escape(repr(site_id), out.write('<h1 id="%s" title="%s">%s</h1>' % (i, escape(repr(site_id),
quote=True), html_site_caption_dict[site_id])) quote=True), html_site_caption_dict[site_id]))
...@@ -1181,6 +1185,7 @@ def asHTML(out, encoding, per_site, args, default_site, period_parameter_dict, ...@@ -1181,6 +1185,7 @@ def asHTML(out, encoding, per_site, args, default_site, period_parameter_dict,
apdex_y_min=apdex_y_min, hit_y_min=hit_y_min, hit_y_max=hit_y_max, apdex_y_min=apdex_y_min, hit_y_min=hit_y_min, hit_y_max=hit_y_max,
apdex_y_scale=apdex_y_scale, apdex_y_scale=apdex_y_scale,
hit_y_scale=hit_y_scale, hit_y_scale=hit_y_scale,
n_hottest_pages=n_hottest_pages,
)) ))
end_stat_time = time.time() end_stat_time = time.time()
if args.stats: if args.stats:
...@@ -1330,6 +1335,9 @@ def main(): ...@@ -1330,6 +1335,9 @@ def main():
group.add_argument('--hit-yscale', default='linear', group.add_argument('--hit-yscale', default='linear',
choices=hit_y_scale_dict, choices=hit_y_scale_dict,
help='hit graph ordinate scale. Default: %(default)s') help='hit graph ordinate scale. Default: %(default)s')
group.add_argument('--n-hottest-pages', type=int,
default=N_HOTTEST_PAGES_DEFAULT,
help='Number of hottest pages to display.')
group = parser.add_argument_group('site matching', 'Earlier arguments take ' group = parser.add_argument_group('site matching', 'Earlier arguments take '
'precedence. Arguments are Python regexes, matching urlencoded strings.' 'precedence. Arguments are Python regexes, matching urlencoded strings.'
......
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