function apachesolr_stats_report in Apache Solr Statistics 6.3
Same name and namespace in other branches
- 6 apachesolr_stats.module \apachesolr_stats_report()
- 7 apachesolr_stats.module \apachesolr_stats_report()
Callback for admin/reports/apachesolr/stats.
@internal param string $granularity Granularity to use for report.* Granularity to use for report.
Parameters
array $search_page:
string $picked_granularity:
Return value
string The page output as HTML.
See also
1 string reference to 'apachesolr_stats_report'
- apachesolr_stats_menu in ./
apachesolr_stats.module - Implementation of hook_menu().
File
- ./
apachesolr_stats.module, line 268 - Keeps and reports statistics about Apache Solr usage and performance.
Code
function apachesolr_stats_report($search_page = NULL, $picked_granularity = "minute") {
$enabled_pages = variable_get('apachesolr_stats_enabled', array());
// If not given a search_page argument, show a listing.
if (empty($search_page)) {
$search_pages = apachesolr_search_load_all_search_pages();
$items = array();
foreach ($search_pages as $search_page) {
$items[] = l($search_page['label'], 'admin/reports/apachesolr_stats/' . $search_page['page_id']);
}
$output = t('Pick a search page to view the report:');
$output .= theme('item_list', $items);
return $output;
}
drupal_set_title(t("Apache Solr statistics report: @label", array(
'@label' => $search_page['label'],
)));
$disabled = true;
if (isset($enabled_pages[$search_page['page_id']]) && $enabled_pages[$search_page['page_id']]) {
$disabled = false;
}
if ($disabled) {
drupal_set_message('Logging is disabled for this page in the !link. Enable it to log Apache Solr queries.', array(
'!link' => l('configuration page', 'admin/settings/apachesolr/stats'),
));
}
$granularities = apachesolr_stats_get_granularities();
// Decide what granularity to use: minute, hour or day
// Check if given argument exists; if not, reset to "hour"
if (!isset($granularities[$picked_granularity])) {
$picked_granularity = "minute";
}
$granularity = $granularities[$picked_granularity];
// Process latest log entries
$report_elements = apachesolr_stats_generate_report_elements($search_page['page_id'], $granularity);
// Create the output HTML:::::::::::::::::::::::::::::::::::::
// Granularity picker:
// Leave only those less than apachesolr_stats_flush_log_timer
$timer_max = variable_get('apachesolr_stats_flush_log_timer', 259200);
$output = "<div class='granularity'>" . t('Choose the report time span:');
foreach ($granularities as $name => $granularity) {
if ($name != "all" && $granularity['time_before'] > $timer_max) {
continue;
}
$output .= " ";
if ($name != $picked_granularity) {
$output .= l($granularity["last_msg"], "admin/reports/apachesolr_stats/" . $search_page['page_id'] . '/' . $name);
}
else {
$output .= "<strong>" . $granularity["last_msg"] . "</strong>";
}
}
$output .= "</div><hr>";
if ($report_elements) {
// Report description
$output .= t('This is an overview of Apache Solr usage and performance.');
$output .= ' ' . t('You can also visit the <a href="@settings-url">settings page</a>.', array(
'@settings-url' => url('admin/settings/apachesolr/stats'),
));
// Render report elements
foreach ($report_elements as $id => $data) {
// Table data
$rows[] = array(
"data" => array(
array(
'data' => $data['name'],
'header' => true,
'style' => 'width:33%',
),
array(
'data' => $data['value'],
),
),
);
}
$output .= theme('table', array(), $rows);
}
else {
drupal_set_message(t('There is not enough stored data to build a report for the current time span.'));
}
return $output;
}