Get Statistics
-
Statistics can be retrieved for the database and for collections.
-
By default, statistics are retrieved for the database defined in the Document Store.
To get database and collection statistics for another database use forDatabase. -
In this page:
Get collection statistics
To get collection statistics, use GetCollectionStatisticsOperation
:
// Pass an instance of class `GetCollectionStatisticsOperation` to the store
/** @var CollectionStatistics $stats */
$stats = $store->maintenance()->send((new GetCollectionStatisticsOperation());
Statistics are returned in the CollectionStatistics
object.
// Collection stats results:
class CollectionStatistics
{
// Total # of documents in all collections
private ?int $countOfDocuments = null;
// Total # of conflicts
private ?int $countOfConflicts = null;
// Total # of documents per collection
private array $collections = [];
// ... getters and setters
}
Get detailed collection statistics
To get detailed collection statistics, use GetDetailedCollectionStatisticsOperation
:
// Pass an instance of class `GetDetailedCollectionStatisticsOperation` to the store
/** @var DetailedCollectionStatistics $stats */
$stats = $store->maintenance()->send(new GetDetailedCollectionStatisticsOperation());
Statistics are returned in the DetailedCollectionStatistics
object.
// Detailed collection stats results:
public class DetailedCollectionStatistics
{
// Total # of documents in all collections
public long CountOfDocuments { get; set; }
// Total # of conflicts
public long CountOfConflicts { get; set; }
// Collection details per collection
public Dictionary<string, CollectionDetails> Collections { get; set; }
}
// Details per collection
class CollectionDetails
{
private ?string $name = null;
private ?int $countOfDocuments = null;
private ?Size $size = null;
private ?Size $documentsSize = null;
private ?Size $tombstonesSize = null;
private ?Size $revisionsSize = null;
// ... getters and setters
}
Get database statistics
To get database statistics, use GetStatisticsOperation
:
// Pass an instance of class `GetStatisticsOperation` to the store
/** @var DatabaseStatistics $stats */
$stats = $store->maintenance()->send(new GetStatisticsOperation());
Statistics are returned in the DatabaseStatistics
object.
// Database stats results:
class DatabaseStatistics implements ResultInterface
{
private ?int $lastDocEtag = null; // Last document etag in database
private ?int $lastDatabaseEtag = null; // Last database etag
private ?int $countOfIndexes = null; // Total # of indexes in database
private ?int $countOfDocuments = null; // Total # of documents in database
private ?int $countOfRevisionDocuments = null; // Total # of revision documents in database
private ?int $countOfDocumentsConflicts = null; // Total # of documents conflicts in database
private ?int $countOfTombstones = null; // Total # of tombstones in database
private ?int $countOfConflicts = null; // Total # of conflicts in database
private ?int $countOfAttachments = null; // Total # of attachments in database
private ?int $countOfUniqueAttachments = null; // Total # of unique attachments in database
private ?int $countOfCounterEntries = null; // Total # of counter-group entries in database
private ?int $countOfTimeSeriesSegments = null; // Total # of time-series segments in database
// List of stale index names in database
public function getStaleIndexes(): IndexInformationArray
{
return IndexInformationArray::fromArray(
array_map(
function (IndexInformation $index) {
return $index->isStale();
},
$this->indexes->getArrayCopy())
);
}
// Statistics for each index in database
private ?IndexInformationArray $indexes = null;
private ?string $databaseChangeVector = null; // Global change vector of the database
private ?string $databaseId = null; // Database identifier
private bool $is64Bit = false; // Indicates if process is 64-bit
private ?string $pager = null; // Component handling the memory-mapped files
private ?DateTimeInterface $lastIndexingTime = null; // Last time of indexing an item
private ?Size $sizeOnDisk = null; // Database size on disk
private ?Size $tempBuffersSizeOnDisk = null; // Temp buffers size on disk
private ?int $numberOfTransactionMergerQueueOperations = null;
// ... getters and setters
}
Get detailed database statistics
To get detailed database statistics, use GetDetailedStatisticsOperation
:
// Pass an instance of class `GetDetailedStatisticsOperation` to the store
/** @var DetailedDatabaseStatistics $stats */
$stats = $store->maintenance()->send(new GetDetailedStatisticsOperation());
Statistics are returned in the DetailedDatabaseStatistics
object.
// Detailed database stats results:
class DetailedDatabaseStatistics extends DatabaseStatistics implements ResultInterface
{
// Total # of identities in database
private ?int $countOfIdentities = null;
// Total # of compare-exchange items in database
private ?int $countOfCompareExchange = null;
// Total # of cmpXchg tombstones in database
private ?int $countOfCompareExchangeTombstones = null;
// Total # of TS deleted ranges values in database
private ?int $countOfTimeSeriesDeletedRanges = null;
// ... getters and setters
}
Get statistics for another database
- By default, you get statistics for the database defined in your Document Store.
- Use
forDatabase
to get database and collection statistics for another database. forDatabase
can be used with any of the above statistics options.
// Get stats for 'AnotherDatabase':
/** @var DatabaseStatistics $stats */
$stats = $store->maintenance()->forDatabase("AnotherDatabase")->send(new GetStatisticsOperation());
- Learn more about switching operations to another database here.