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