首页 > 解决方案 > gcp:datastore - 使用 Python API 获取总体状态 __Stat_Total__

问题描述

我想获取仪表板应用程序的整体数据存储统计信息。我浏览了文档,没有关于如何使用数据存储获取统计信息的教程。以某种方式获取状态详细信息有
SELECT * FROM __Stat_Total__显示的 GQL 查询
builtin_index_bytes, builtin_index_count, bytes, composite_index_bytes, composite_index_count, count, entity_bytes, timestamp
我想通过 Python API 客户端显示所有这些细节。

我尝试了一些没有成功的例子。

def get_summary_statistics(self):
        #[START getting the Summary Statistics]
        stats = self.client.query(kind= self.kind_name)
        overall_stats = stats.__Stat_Total__ ()

        return overall_stats

如何获取所有数据存储统计信息?

标签: python-3.xgoogle-cloud-platformgoogle-cloud-datastore

解决方案


Cloud Datastore NDB 管理文档包含有关和其他统计实体的一些信息,__Stat_Total__以及一个查询 Datastore 统计信息的小示例脚本:

from google.appengine.ext.ndb import stats

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

推荐阅读