/[drupal]/contributions/modules/ab/ab.admin.inc
ViewVC logotype

Contents of /contributions/modules/ab/ab.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Mon Sep 22 15:25:49 2008 UTC (14 months ago) by tjholowaychuk
Branch: MAIN
CVS Tags: DRUPAL-6--1-0, HEAD
Changes since 1.3: +2 -2 lines
File MIME type: text/x-php
- Updated changelog
- Updated readme
1 <?php
2 // $Id: ab.admin.inc,v 1.3 2008/09/12 18:32:37 tjholowaychuk Exp $
3
4 /**
5 * @file
6 * ApacheBench administration and reporting pages.
7 */
8
9 /* -----------------------------------------------------------------
10
11 Administration
12
13 ------------------------------------------------------------------ */
14
15 /**
16 * Settings form.
17 *
18 * @return array
19 *
20 * @ingroup forms
21 */
22 function ab_settings() {
23 $form = array();
24
25 $form['ab_frequency'] = array(
26 '#type' => 'textfield',
27 '#title' => t('Frequency'),
28 '#description' => t('Run ApacheBench tests every x hours. Cron must be scheduled to run at this same frequency or higher. Set to 0 to prevent automated testing.'),
29 '#default_value' => variable_get('ab_frequency', 0),
30 );
31 $form['ab_requests'] = array(
32 '#type' => 'textfield',
33 '#title' => t('Requests'),
34 '#description' => t('Total number of requests.'),
35 '#default_value' => variable_get('ab_requests', 100),
36 );
37 $form['ab_concurrency'] = array(
38 '#type' => 'textfield',
39 '#title' => t('Concurrency'),
40 '#description' => t('Number of concurrenct requests.'),
41 '#default_value' => variable_get('ab_concurrency', 25),
42 );
43 $form['ab_uris'] = array(
44 '#type' => 'textarea',
45 '#title' => t('Website URIs'),
46 '#description' => t('One absolute URI per line, be sure to include a trailing slash (/) for example <em>http://vision-media.ca/</em>.'),
47 '#default_value' => variable_get('ab_uris', ''),
48 );
49
50 return system_settings_form($form);
51 }
52
53 /* -----------------------------------------------------------------
54
55 Reporting
56
57 ------------------------------------------------------------------ */
58
59 /**
60 * Display ApacheBench reports when charting is available.
61 *
62 * @return string
63 * Markup.
64 */
65 function ab_reports() {
66 $output = ' ';
67
68 if (!module_exists('open_flash_chart_api')){
69 drupal_set_message(t('In order to view these reports you must install the <a href="http://drupal.org/project/open_flash_chart_api">open_flash_chart_api</a> module.'));
70 }
71 else {
72 ab_require_chart();
73 $output .= ab_get_overview_report();
74 }
75
76 return $output;
77 }
78
79 /**
80 * Create overview report.
81 *
82 * @return string
83 * Markup.
84 */
85 function ab_get_overview_report() {
86 $output = '';
87 $rows = array();
88 $header = array(t('URI'), t('Avg requests per second'), t('Total tests'), t('Avg requests'), t('Avg concurrency'), t('Avg failed'), t('Avg document length'), t('Avg time taken'));
89
90 // @todo finish charts, remove table reports
91 // @todo utilize tablesort api
92
93 // Fetch results
94 $results = db_query("
95 SELECT
96 uri,
97 COUNT(*) as total_tests,
98 AVG(concurrency) as avg_concurrency,
99 AVG(requests) as avg_requests,
100 AVG(requests_per_second) as avg_requests_per_second,
101 AVG(failed_requests) as avg_failed_requests,
102 AVG(time_taken_for_tests) as avg_time_taken_for_tests,
103 AVG(document_length) as avg_document_length
104 FROM {ab_results}
105 GROUP BY uri
106 ORDER BY AVG(requests_per_second) DESC
107 ");
108 while ($result = db_fetch_object($results)) {
109 $rows[] = array(
110 $result->uri,
111 floor($result->avg_requests_per_second),
112 floor($result->total_tests),
113 floor($result->avg_requests),
114 floor($result->avg_concurrency),
115 floor($result->avg_failed_requests),
116 format_size($result->avg_document_length),
117 t('%time seconds', array('%time' => round($result->avg_time_taken_for_tests, 2))),
118 );
119 }
120
121 // Display results
122 $output .= theme('table', $header, $rows);
123
124 return $output;
125 }
126

  ViewVC Help
Powered by ViewVC 1.1.2