This repository was archived by the owner on Dec 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathstats.py
More file actions
467 lines (350 loc) · 16.6 KB
/
stats.py
File metadata and controls
467 lines (350 loc) · 16.6 KB
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
#
# Copyright 2008 The ndb Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Models to be used when accessing app specific datastore usage statistics.
These entities cannot be created by users, but are populated in the
application's datastore by offline processes run by the Google App Engine team.
"""
# NOTE: All constant strings in this file should be kept in sync with
# those in google/appengine/ext/db/stats.py.
from . import model
__all__ = ['BaseKindStatistic',
'BaseStatistic',
'GlobalStat',
'KindCompositeIndexStat',
'KindNonRootEntityStat',
'KindPropertyNamePropertyTypeStat',
'KindPropertyNameStat',
'KindPropertyTypeStat',
'KindRootEntityStat',
'KindStat',
'NamespaceGlobalStat',
'NamespaceKindCompositeIndexStat',
'NamespaceKindNonRootEntityStat',
'NamespaceKindPropertyNamePropertyTypeStat',
'NamespaceKindPropertyNameStat',
'NamespaceKindPropertyTypeStat',
'NamespaceKindRootEntityStat',
'NamespaceKindStat',
'NamespacePropertyTypeStat',
'NamespaceStat',
'PropertyTypeStat',
]
class BaseStatistic(model.Model):
"""Base Statistic Model class.
Attributes:
bytes: the total number of bytes taken up in Cloud Datastore for the
statistic instance.
count: attribute is the total number of occurrences of the statistic
in Cloud Datastore.
timestamp: the time the statistic instance was written to Cloud Datastore.
"""
# This is necessary for the _get_kind() classmethod override.
STORED_KIND_NAME = '__BaseStatistic__'
# The number of bytes that is taken up.
bytes = model.IntegerProperty()
# The number of entity records.
count = model.IntegerProperty()
# When this statistic was inserted into Cloud Datastore.
timestamp = model.DateTimeProperty()
@classmethod
def _get_kind(cls):
"""Kind name override."""
return cls.STORED_KIND_NAME
class BaseKindStatistic(BaseStatistic):
"""Base Statistic Model class for stats associated with kinds.
Attributes:
kind_name: the name of the kind associated with the statistic instance.
entity_bytes: the number of bytes taken up to store the statistic
in Cloud Datastore minus the cost of storing indices.
"""
# This is necessary for the _get_kind() classmethod override.
STORED_KIND_NAME = '__BaseKindStatistic__'
# The name of the kind.
kind_name = model.StringProperty()
# The number of bytes that is taken up in entity table. entity_bytes does not
# reflect the storage allocated for indexes, either built-in or composite
# indexes.
entity_bytes = model.IntegerProperty(default=0L)
class GlobalStat(BaseStatistic):
"""An aggregate of all entities across the entire application.
This statistic only has a single instance in Cloud Datastore that contains the
total number of entities stored and the total number of bytes they take up.
Attributes:
entity_bytes: the number of bytes taken up to store the statistic
in Cloud Datastore minus the cost of storing indices.
builtin_index_bytes: the number of bytes taken up to store builtin-in
index entries
builtin_index_count: the number of built-in index entries.
composite_index_bytes: the number of bytes taken up to store composite
index entries
composite_index_count: the number of composite index entries.
"""
STORED_KIND_NAME = '__Stat_Total__'
# The number of bytes that is taken up in entity storage.
entity_bytes = model.IntegerProperty(default=0L)
# The number of bytes taken up for built-in index entries.
builtin_index_bytes = model.IntegerProperty(default=0L)
# The number of built-in index entries.
builtin_index_count = model.IntegerProperty(default=0L)
# The number of bytes taken up for composite index entries.
composite_index_bytes = model.IntegerProperty(default=0L)
# The number of composite indexes entries.
composite_index_count = model.IntegerProperty(default=0L)
class NamespaceStat(BaseStatistic):
"""An aggregate of all entities across an entire namespace.
This statistic has one instance per namespace. The key_name is the
represented namespace. NamespaceStat entities will only be found
in the namespace "" (empty string). It contains the total
number of entities stored and the total number of bytes they take up.
Attributes:
subject_namespace: the namespace associated with the statistic instance.
entity_bytes: the number of bytes taken up to store the statistic
in Cloud Datastore minus the cost of storing indices.
builtin_index_bytes: the number of bytes taken up to store builtin-in
index entries
builtin_index_count: the number of built-in index entries.
composite_index_bytes: the number of bytes taken up to store composite
index entries
composite_index_count: the number of composite index entries.
"""
STORED_KIND_NAME = '__Stat_Namespace__'
# The namespace name this NamespaceStat refers to.
subject_namespace = model.StringProperty()
# The number of bytes that is taken up in entity storage.
entity_bytes = model.IntegerProperty(default=0L)
# The number of bytes taken up for built-in index entries.
builtin_index_bytes = model.IntegerProperty(default=0L)
# The number of built-in index entries.
builtin_index_count = model.IntegerProperty(default=0L)
# The number of bytes taken up for composite index entries.
composite_index_bytes = model.IntegerProperty(default=0L)
# The number of composite indexes entries.
composite_index_count = model.IntegerProperty(default=0L)
class KindStat(BaseKindStatistic):
"""An aggregate of all entities at the granularity of their Kind.
There is an instance of the KindStat for every Kind that is in the
application's datastore. This stat contains per-Kind statistics.
Attributes:
builtin_index_bytes: the number of bytes taken up to store builtin-in
index entries
builtin_index_count: the number of built-in index entries.
composite_index_bytes: the number of bytes taken up to store composite
index entries
composite_index_count: the number of composite index entries.
"""
STORED_KIND_NAME = '__Stat_Kind__'
# The number of bytes taken up for built-in index entries.
builtin_index_bytes = model.IntegerProperty(default=0L)
# The number of built-in index entries.
builtin_index_count = model.IntegerProperty(default=0L)
# The number of bytes taken up for composite index entries.
composite_index_bytes = model.IntegerProperty(default=0L)
# The number of composite indexes entries.
composite_index_count = model.IntegerProperty(default=0L)
class KindRootEntityStat(BaseKindStatistic):
"""Statistics of the number of root entities in Cloud Datastore by Kind.
There is an instance of the KindRootEntityState for every Kind that is in the
application's datastore and has an instance that is a root entity. This stat
contains statistics regarding these root entity instances.
"""
STORED_KIND_NAME = '__Stat_Kind_IsRootEntity__'
class KindNonRootEntityStat(BaseKindStatistic):
"""Statistics of the number of non root entities in Cloud Datastore by Kind.
There is an instance of the KindNonRootEntityStat for every Kind that is in
the application's datastore that is a not a root entity. This stat contains
statistics regarding thse non root entity instances.
"""
STORED_KIND_NAME = '__Stat_Kind_NotRootEntity__'
class PropertyTypeStat(BaseStatistic):
"""An aggregate of all properties across the entire application by type.
There is an instance of the PropertyTypeStat for every property type
(google.appengine.api.datastore_types._PROPERTY_TYPES) in use by the
application in its datastore.
Attributes:
property_type: the property type associated with the statistic instance.
entity_bytes: the number of bytes taken up to store the statistic
in Cloud Datastore minus the cost of storing indices.
builtin_index_bytes: the number of bytes taken up to store builtin-in
index entries
builtin_index_count: the number of built-in index entries.
"""
STORED_KIND_NAME = '__Stat_PropertyType__'
# The name of the property_type.
property_type = model.StringProperty()
# The number of bytes that is taken up in entity storage.
entity_bytes = model.IntegerProperty(default=0L)
# The number of bytes taken up for built-in index entries.
builtin_index_bytes = model.IntegerProperty(default=0L)
# The number of built-in index entries.
builtin_index_count = model.IntegerProperty(default=0L)
class KindPropertyTypeStat(BaseKindStatistic):
"""Statistics on (kind, property_type) tuples in the app's datastore.
There is an instance of the KindPropertyTypeStat for every
(kind, property_type) tuple in the application's datastore.
Attributes:
property_type: the property type associated with the statistic instance.
builtin_index_bytes: the number of bytes taken up to store builtin-in
index entries
builtin_index_count: the number of built-in index entries.
"""
STORED_KIND_NAME = '__Stat_PropertyType_Kind__'
# The name of the property_type.
property_type = model.StringProperty()
# The number of bytes taken up for built-in index entries.
builtin_index_bytes = model.IntegerProperty(default=0L)
# The number of built-in index entries.
builtin_index_count = model.IntegerProperty(default=0L)
class KindPropertyNameStat(BaseKindStatistic):
"""Statistics on (kind, property_name) tuples in the app's datastore.
There is an instance of the KindPropertyNameStat for every
(kind, property_name) tuple in the application's datastore.
Attributes:
property_name: the name of the property associated with the statistic
instance.
builtin_index_bytes: the number of bytes taken up to store builtin-in
index entries
builtin_index_count: the number of built-in index entries.
"""
STORED_KIND_NAME = '__Stat_PropertyName_Kind__'
# The name of the property.
property_name = model.StringProperty()
# The number of bytes taken up for built-in index entries.
builtin_index_bytes = model.IntegerProperty(default=0L)
# The number of built-in index entries.
builtin_index_count = model.IntegerProperty(default=0L)
class KindPropertyNamePropertyTypeStat(BaseKindStatistic):
"""Statistic on (kind, property_name, property_type) tuples in Cloud
Datastore.
There is an instance of the KindPropertyNamePropertyTypeStat for every
(kind, property_name, property_type) tuple in the application's datastore.
Attributes:
property_type: the property type associated with the statistic instance.
property_name: the name of the property associated with the statistic
instance.
builtin_index_bytes: the number of bytes taken up to store builtin-in
index entries
builtin_index_count: the number of built-in index entries.
"""
STORED_KIND_NAME = '__Stat_PropertyType_PropertyName_Kind__'
# The name of the property type.
property_type = model.StringProperty()
# The name of the property.
property_name = model.StringProperty()
# The number of bytes taken up for built-in index entries.
builtin_index_bytes = model.IntegerProperty(default=0L)
# The number of built-in index entries.
builtin_index_count = model.IntegerProperty(default=0L)
class KindCompositeIndexStat(BaseStatistic):
"""Statistic on (kind, composite_index_id) tuples in Cloud Datastore.
There is an instance of the KindCompositeIndexStat for every unique
(kind, composite_index_id) tuple in the application's datastore indexes.
Attributes:
index_id: the id of the composite index associated with the statistic
instance.
kind_name: the name of the kind associated with the statistic instance.
"""
STORED_KIND_NAME = '__Stat_Kind_CompositeIndex__'
# The id of the composite index
index_id = model.IntegerProperty()
# The name of the kind.
kind_name = model.StringProperty()
# The following specify namespace-specific stats.
# These types are specific to Cloud Datastore namespace they are located
# within. These will only be produced if datastore entities exist
# in a namespace other than the empty namespace (i.e. namespace="").
class NamespaceGlobalStat(GlobalStat):
"""GlobalStat equivalent for a specific namespace.
These may be found in each specific namespace and represent stats for
that particular namespace.
"""
STORED_KIND_NAME = '__Stat_Ns_Total__'
class NamespaceKindStat(KindStat):
"""KindStat equivalent for a specific namespace.
These may be found in each specific namespace and represent stats for
that particular namespace.
"""
STORED_KIND_NAME = '__Stat_Ns_Kind__'
class NamespaceKindRootEntityStat(KindRootEntityStat):
"""KindRootEntityStat equivalent for a specific namespace.
These may be found in each specific namespace and represent stats for
that particular namespace.
"""
STORED_KIND_NAME = '__Stat_Ns_Kind_IsRootEntity__'
class NamespaceKindNonRootEntityStat(KindNonRootEntityStat):
"""KindNonRootEntityStat equivalent for a specific namespace.
These may be found in each specific namespace and represent stats for
that particular namespace.
"""
STORED_KIND_NAME = '__Stat_Ns_Kind_NotRootEntity__'
class NamespacePropertyTypeStat(PropertyTypeStat):
"""PropertyTypeStat equivalent for a specific namespace.
These may be found in each specific namespace and represent stats for
that particular namespace.
"""
STORED_KIND_NAME = '__Stat_Ns_PropertyType__'
class NamespaceKindPropertyTypeStat(KindPropertyTypeStat):
"""KindPropertyTypeStat equivalent for a specific namespace.
These may be found in each specific namespace and represent stats for
that particular namespace.
"""
STORED_KIND_NAME = '__Stat_Ns_PropertyType_Kind__'
class NamespaceKindPropertyNameStat(KindPropertyNameStat):
"""KindPropertyNameStat equivalent for a specific namespace.
These may be found in each specific namespace and represent stats for
that particular namespace.
"""
STORED_KIND_NAME = '__Stat_Ns_PropertyName_Kind__'
class NamespaceKindPropertyNamePropertyTypeStat(
KindPropertyNamePropertyTypeStat):
"""KindPropertyNamePropertyTypeStat equivalent for a specific namespace.
These may be found in each specific namespace and represent stats for
that particular namespace.
"""
STORED_KIND_NAME = '__Stat_Ns_PropertyType_PropertyName_Kind__'
class NamespaceKindCompositeIndexStat(KindCompositeIndexStat):
"""KindCompositeIndexStat equivalent for a specific namespace.
These may be found in each specific namespace and represent stats for
that particular namespace.
"""
STORED_KIND_NAME = '__Stat_Ns_Kind_CompositeIndex__'
# Maps a datastore stat entity kind name to its respective model class.
# NOTE: Any new stats added to this module should also be added here.
_DATASTORE_STATS_CLASSES_BY_KIND = {
GlobalStat.STORED_KIND_NAME: GlobalStat,
NamespaceStat.STORED_KIND_NAME: NamespaceStat,
KindStat.STORED_KIND_NAME: KindStat,
KindRootEntityStat.STORED_KIND_NAME: KindRootEntityStat,
KindNonRootEntityStat.STORED_KIND_NAME: KindNonRootEntityStat,
PropertyTypeStat.STORED_KIND_NAME: PropertyTypeStat,
KindPropertyTypeStat.STORED_KIND_NAME: KindPropertyTypeStat,
KindPropertyNameStat.STORED_KIND_NAME: KindPropertyNameStat,
KindPropertyNamePropertyTypeStat.STORED_KIND_NAME:
KindPropertyNamePropertyTypeStat,
KindCompositeIndexStat.STORED_KIND_NAME: KindCompositeIndexStat,
NamespaceGlobalStat.STORED_KIND_NAME: NamespaceGlobalStat,
NamespaceKindStat.STORED_KIND_NAME: NamespaceKindStat,
NamespaceKindRootEntityStat.STORED_KIND_NAME: NamespaceKindRootEntityStat,
NamespaceKindNonRootEntityStat.STORED_KIND_NAME:
NamespaceKindNonRootEntityStat,
NamespacePropertyTypeStat.STORED_KIND_NAME: NamespacePropertyTypeStat,
NamespaceKindPropertyTypeStat.STORED_KIND_NAME:
NamespaceKindPropertyTypeStat,
NamespaceKindPropertyNameStat.STORED_KIND_NAME:
NamespaceKindPropertyNameStat,
NamespaceKindPropertyNamePropertyTypeStat.STORED_KIND_NAME:
NamespaceKindPropertyNamePropertyTypeStat,
NamespaceKindCompositeIndexStat.STORED_KIND_NAME:
NamespaceKindCompositeIndexStat,
}