stats.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. import type { Document } from '../bson';
  2. import type { Collection } from '../collection';
  3. import type { Db } from '../db';
  4. import type { Server } from '../sdam/server';
  5. import type { ClientSession } from '../sessions';
  6. import type { Callback } from '../utils';
  7. import { CommandCallbackOperation, type CommandOperationOptions } from './command';
  8. import { Aspect, defineAspects } from './operation';
  9. /**
  10. * @public
  11. * @deprecated the `collStats` operation will be removed in the next major release. Please
  12. * use an aggregation pipeline with the [`$collStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/) stage instead
  13. */
  14. export interface CollStatsOptions extends CommandOperationOptions {
  15. /** Divide the returned sizes by scale value. */
  16. scale?: number;
  17. }
  18. /**
  19. * Get all the collection statistics.
  20. * @internal
  21. */
  22. export class CollStatsOperation extends CommandCallbackOperation<Document> {
  23. override options: CollStatsOptions;
  24. collectionName: string;
  25. /**
  26. * Construct a Stats operation.
  27. *
  28. * @param collection - Collection instance
  29. * @param options - Optional settings. See Collection.prototype.stats for a list of options.
  30. */
  31. constructor(collection: Collection, options?: CollStatsOptions) {
  32. super(collection, options);
  33. this.options = options ?? {};
  34. this.collectionName = collection.collectionName;
  35. }
  36. override executeCallback(
  37. server: Server,
  38. session: ClientSession | undefined,
  39. callback: Callback<CollStats>
  40. ): void {
  41. const command: Document = { collStats: this.collectionName };
  42. if (this.options.scale != null) {
  43. command.scale = this.options.scale;
  44. }
  45. super.executeCommandCallback(server, session, command, callback);
  46. }
  47. }
  48. /** @public */
  49. export interface DbStatsOptions extends CommandOperationOptions {
  50. /** Divide the returned sizes by scale value. */
  51. scale?: number;
  52. }
  53. /** @internal */
  54. export class DbStatsOperation extends CommandCallbackOperation<Document> {
  55. override options: DbStatsOptions;
  56. constructor(db: Db, options: DbStatsOptions) {
  57. super(db, options);
  58. this.options = options;
  59. }
  60. override executeCallback(
  61. server: Server,
  62. session: ClientSession | undefined,
  63. callback: Callback<Document>
  64. ): void {
  65. const command: Document = { dbStats: true };
  66. if (this.options.scale != null) {
  67. command.scale = this.options.scale;
  68. }
  69. super.executeCommandCallback(server, session, command, callback);
  70. }
  71. }
  72. /**
  73. * @deprecated the `collStats` operation will be removed in the next major release. Please
  74. * use an aggregation pipeline with the [`$collStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/) stage instead
  75. * @public
  76. * @see https://www.mongodb.com/docs/manual/reference/command/collStats/
  77. */
  78. export interface CollStats extends Document {
  79. /** Namespace */
  80. ns: string;
  81. /** Number of documents */
  82. count: number;
  83. /** Collection size in bytes */
  84. size: number;
  85. /** Average object size in bytes */
  86. avgObjSize: number;
  87. /** (Pre)allocated space for the collection in bytes */
  88. storageSize: number;
  89. /** Number of extents (contiguously allocated chunks of datafile space) */
  90. numExtents: number;
  91. /** Number of indexes */
  92. nindexes: number;
  93. /** Size of the most recently created extent in bytes */
  94. lastExtentSize: number;
  95. /** Padding can speed up updates if documents grow */
  96. paddingFactor: number;
  97. /** A number that indicates the user-set flags on the collection. userFlags only appears when using the mmapv1 storage engine */
  98. userFlags?: number;
  99. /** Total index size in bytes */
  100. totalIndexSize: number;
  101. /** Size of specific indexes in bytes */
  102. indexSizes: {
  103. _id_: number;
  104. [index: string]: number;
  105. };
  106. /** `true` if the collection is capped */
  107. capped: boolean;
  108. /** The maximum number of documents that may be present in a capped collection */
  109. max: number;
  110. /** The maximum size of a capped collection */
  111. maxSize: number;
  112. /** This document contains data reported directly by the WiredTiger engine and other data for internal diagnostic use */
  113. wiredTiger?: WiredTigerData;
  114. /** The fields in this document are the names of the indexes, while the values themselves are documents that contain statistics for the index provided by the storage engine */
  115. indexDetails?: any;
  116. ok: number;
  117. /** The amount of storage available for reuse. The scale argument affects this value. */
  118. freeStorageSize?: number;
  119. /** An array that contains the names of the indexes that are currently being built on the collection */
  120. indexBuilds?: number;
  121. /** The sum of the storageSize and totalIndexSize. The scale argument affects this value */
  122. totalSize: number;
  123. /** The scale value used by the command. */
  124. scaleFactor: number;
  125. }
  126. /**
  127. * @public
  128. * @deprecated This type is only used for the deprecated `collStats` operation and will be removed in the next major release.
  129. */
  130. export interface WiredTigerData extends Document {
  131. LSM: {
  132. 'bloom filter false positives': number;
  133. 'bloom filter hits': number;
  134. 'bloom filter misses': number;
  135. 'bloom filter pages evicted from cache': number;
  136. 'bloom filter pages read into cache': number;
  137. 'bloom filters in the LSM tree': number;
  138. 'chunks in the LSM tree': number;
  139. 'highest merge generation in the LSM tree': number;
  140. 'queries that could have benefited from a Bloom filter that did not exist': number;
  141. 'sleep for LSM checkpoint throttle': number;
  142. 'sleep for LSM merge throttle': number;
  143. 'total size of bloom filters': number;
  144. } & Document;
  145. 'block-manager': {
  146. 'allocations requiring file extension': number;
  147. 'blocks allocated': number;
  148. 'blocks freed': number;
  149. 'checkpoint size': number;
  150. 'file allocation unit size': number;
  151. 'file bytes available for reuse': number;
  152. 'file magic number': number;
  153. 'file major version number': number;
  154. 'file size in bytes': number;
  155. 'minor version number': number;
  156. };
  157. btree: {
  158. 'btree checkpoint generation': number;
  159. 'column-store fixed-size leaf pages': number;
  160. 'column-store internal pages': number;
  161. 'column-store variable-size RLE encoded values': number;
  162. 'column-store variable-size deleted values': number;
  163. 'column-store variable-size leaf pages': number;
  164. 'fixed-record size': number;
  165. 'maximum internal page key size': number;
  166. 'maximum internal page size': number;
  167. 'maximum leaf page key size': number;
  168. 'maximum leaf page size': number;
  169. 'maximum leaf page value size': number;
  170. 'maximum tree depth': number;
  171. 'number of key/value pairs': number;
  172. 'overflow pages': number;
  173. 'pages rewritten by compaction': number;
  174. 'row-store internal pages': number;
  175. 'row-store leaf pages': number;
  176. } & Document;
  177. cache: {
  178. 'bytes currently in the cache': number;
  179. 'bytes read into cache': number;
  180. 'bytes written from cache': number;
  181. 'checkpoint blocked page eviction': number;
  182. 'data source pages selected for eviction unable to be evicted': number;
  183. 'hazard pointer blocked page eviction': number;
  184. 'in-memory page passed criteria to be split': number;
  185. 'in-memory page splits': number;
  186. 'internal pages evicted': number;
  187. 'internal pages split during eviction': number;
  188. 'leaf pages split during eviction': number;
  189. 'modified pages evicted': number;
  190. 'overflow pages read into cache': number;
  191. 'overflow values cached in memory': number;
  192. 'page split during eviction deepened the tree': number;
  193. 'page written requiring lookaside records': number;
  194. 'pages read into cache': number;
  195. 'pages read into cache requiring lookaside entries': number;
  196. 'pages requested from the cache': number;
  197. 'pages written from cache': number;
  198. 'pages written requiring in-memory restoration': number;
  199. 'tracked dirty bytes in the cache': number;
  200. 'unmodified pages evicted': number;
  201. } & Document;
  202. cache_walk: {
  203. 'Average difference between current eviction generation when the page was last considered': number;
  204. 'Average on-disk page image size seen': number;
  205. 'Clean pages currently in cache': number;
  206. 'Current eviction generation': number;
  207. 'Dirty pages currently in cache': number;
  208. 'Entries in the root page': number;
  209. 'Internal pages currently in cache': number;
  210. 'Leaf pages currently in cache': number;
  211. 'Maximum difference between current eviction generation when the page was last considered': number;
  212. 'Maximum page size seen': number;
  213. 'Minimum on-disk page image size seen': number;
  214. 'On-disk page image sizes smaller than a single allocation unit': number;
  215. 'Pages created in memory and never written': number;
  216. 'Pages currently queued for eviction': number;
  217. 'Pages that could not be queued for eviction': number;
  218. 'Refs skipped during cache traversal': number;
  219. 'Size of the root page': number;
  220. 'Total number of pages currently in cache': number;
  221. } & Document;
  222. compression: {
  223. 'compressed pages read': number;
  224. 'compressed pages written': number;
  225. 'page written failed to compress': number;
  226. 'page written was too small to compress': number;
  227. 'raw compression call failed, additional data available': number;
  228. 'raw compression call failed, no additional data available': number;
  229. 'raw compression call succeeded': number;
  230. } & Document;
  231. cursor: {
  232. 'bulk-loaded cursor-insert calls': number;
  233. 'create calls': number;
  234. 'cursor-insert key and value bytes inserted': number;
  235. 'cursor-remove key bytes removed': number;
  236. 'cursor-update value bytes updated': number;
  237. 'insert calls': number;
  238. 'next calls': number;
  239. 'prev calls': number;
  240. 'remove calls': number;
  241. 'reset calls': number;
  242. 'restarted searches': number;
  243. 'search calls': number;
  244. 'search near calls': number;
  245. 'truncate calls': number;
  246. 'update calls': number;
  247. };
  248. reconciliation: {
  249. 'dictionary matches': number;
  250. 'fast-path pages deleted': number;
  251. 'internal page key bytes discarded using suffix compression': number;
  252. 'internal page multi-block writes': number;
  253. 'internal-page overflow keys': number;
  254. 'leaf page key bytes discarded using prefix compression': number;
  255. 'leaf page multi-block writes': number;
  256. 'leaf-page overflow keys': number;
  257. 'maximum blocks required for a page': number;
  258. 'overflow values written': number;
  259. 'page checksum matches': number;
  260. 'page reconciliation calls': number;
  261. 'page reconciliation calls for eviction': number;
  262. 'pages deleted': number;
  263. } & Document;
  264. }
  265. defineAspects(CollStatsOperation, [Aspect.READ_OPERATION]);
  266. defineAspects(DbStatsOperation, [Aspect.READ_OPERATION]);