My favorites | English | Sign in

Datastore Statistics in Python

The datastore maintains statistics about the data stored for an application, such as how many entities there are of a given kind, or how much space is used by property values of a given type. You can view these statistics in the Administration Console, under Datastore > Statistics.

You can also access these values programmatically within the application by querying for specially named entites using the datastore API. Each statistic is accessible as an entity whose kind name begins and ends with two underscores. For example, each app has exactly one entity of the kind __Stat_Total__ that represents statistics about all of the entities in the datastore in total. Each statistic entity has the following properties:

  • count, the number of items considered by the statistic (a long integer)
  • bytes, the total size of the items for this statistic (a long integer)
  • timestamp, the time of the most recent update to the statistic (a date-time value)

Some statistic kinds also have additional properties, listed below.

A Python application can use model classes provided by the package google.appengine.ext.db.stats to access statistic entities.

from google.appengine.ext.db import stats

global_stat = stats.GlobalStat.all().get()
print 'Total bytes stored: %d' % global_stat.bytes
print 'Total entities stored: %d' % global_stat.count

When the statistics system creates new statistic entities, it does not delete the old ones right away. The best way to get a consistent view of the statistics is to query for the GlobalStat entity with the most recent timestamp, then use that timestamp value as a filter when fetching other statistic entities.

The statistic entities are included in the calculated statistic values. Statistic entities take up space relative to the number of unique kinds and property names used by the application.

The complete list of available statistics is as follows:

Statistic Stat Entity Kind Description
all entities __Stat_Total__
Python class: GlobalStat

All entities.

entities of a kind __Stat_Kind__
Python class: KindStat

Entities of a kind; one stat entity for each kind of entity stored. Additional properties:

  • kind_name, the name of the kind represented (a string)
root entities of a kind __Stat_Kind_IsRootEntity__
Python class: KindRootEntityStat

Entities of a kind that are entity group root entities (have no ancestor parent); one stat entity for each kind of entity stored. Additional properties:

  • kind_name, the name of the kind represented (a string)
non-root entities of a kind __Stat_Kind_NotRootEntity__
Python class: KindNotRootEntityStat

Entities of a kind that are not entity group root entities (have an ancestor parent); one stat entity for each kind of entity stored. Additional properties:

  • kind_name, the name of the kind represented (a string)
properties of a type __Stat_PropertyType__
Python class: PropertyTypeStat

Properties of a value type across all entities; one stat entity per value type. Additional properties:

  • property_type, the name of the value type (a string)
properties of a type per kind __Stat_PropertyType_Kind__
Python class: KindPropertyTypeStat

Properties of a value type across entities of a given kind; one stat entity per combination of property type and kind. Additional properties:

  • property_type, the name of the value type (a string)
  • kind_name, the name of the kind represented (a string)
properties with a name __Stat_PropertyName_Kind__
Python class: KindPropertyNameStat

Properties with a given name across entities of a given kind; one stat entity per combination of unique property name and kind. Additional properties:

  • property_name, the name of the property (a string)
  • kind_name, the name of the kind represented (a string)
properties of a type and with a name __Stat_PropertyType_PropertyName_Kind__
Python class: KindPropertyNamePropertyTypeStat

Properties with a given name and of a given value type across entities of a given kind; one stat entity per combination of property name, value type and kind that exists in the datastore. Additional properties:

  • property_type, the name of the value type (a string)
  • property_name, the name of the property (a string)
  • kind_name, the name of the kind represented (a string)

Some statistics refer to datastore property value types by name, as strings. These names are as follows:

  • "Blob"
  • "Boolean"
  • "ByteString"
  • "Category"
  • "Date/Time"
  • "Email"
  • "Float"
  • "GeoPt"
  • "Integer"
  • "Key"
  • "Link"
  • "NULL"
  • "PhoneNumber"
  • "PostalAddress"
  • "Rating"
  • "String"
  • "Text"
  • "User"