You are here

public function SolrConnectorPluginBase::getStatsSummary in Search API Solr 8

Same name and namespace in other branches
  1. 8.3 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::getStatsSummary()
  2. 8.2 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::getStatsSummary()
  3. 4.x src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::getStatsSummary()

Gets summary information about the Solr Core.

Return value

array An array of stats about the solr core.

Throws

\Drupal\search_api_solr\SearchApiSolrException

Overrides SolrConnectorInterface::getStatsSummary

File

src/SolrConnector/SolrConnectorPluginBase.php, line 554

Class

SolrConnectorPluginBase
Defines a base class for Solr connector plugins.

Namespace

Drupal\search_api_solr\SolrConnector

Code

public function getStatsSummary() {
  $this
    ->connect();
  $this
    ->useTimeout();
  $summary = array(
    '@pending_docs' => '',
    '@autocommit_time_seconds' => '',
    '@autocommit_time' => '',
    '@deletes_by_id' => '',
    '@deletes_by_query' => '',
    '@deletes_total' => '',
    '@schema_version' => '',
    '@core_name' => '',
    '@index_size' => '',
  );
  $query = $this->solr
    ->createPing();
  $query
    ->setResponseWriter(Query::WT_PHPS);
  $query
    ->setHandler('admin/mbeans?stats=true');
  $stats = $this
    ->execute($query)
    ->getData();
  if (!empty($stats)) {
    $update_handler_stats = $stats['solr-mbeans']['UPDATEHANDLER']['updateHandler']['stats'];
    $summary['@pending_docs'] = (int) $update_handler_stats['docsPending'];
    $max_time = (int) $update_handler_stats['autocommit maxTime'];

    // Convert to seconds.
    $summary['@autocommit_time_seconds'] = $max_time / 1000;
    $summary['@autocommit_time'] = \Drupal::service('date.formatter')
      ->formatInterval($max_time / 1000);
    $summary['@deletes_by_id'] = (int) $update_handler_stats['deletesById'];
    $summary['@deletes_by_query'] = (int) $update_handler_stats['deletesByQuery'];
    $summary['@deletes_total'] = $summary['@deletes_by_id'] + $summary['@deletes_by_query'];
    $summary['@schema_version'] = $this
      ->getSchemaVersionString(TRUE);
    $summary['@core_name'] = $stats['solr-mbeans']['CORE']['core']['stats']['coreName'];
    if (version_compare($this
      ->getSolrVersion(TRUE), '6.4', '>=')) {

      // @see https://issues.apache.org/jira/browse/SOLR-3990
      $summary['@index_size'] = $stats['solr-mbeans']['CORE']['core']['stats']['size'];
    }
    else {
      $summary['@index_size'] = $stats['solr-mbeans']['QUERYHANDLER']['/replication']['stats']['indexSize'];
    }
  }
  return $summary;
}