我想获取数据库的详细信息,或者我想说一下Cosmos DB中存在的所有数据库的吞吐量值,还想检查数据库是否处于活动状态?
是否有相同的API?否则,如何获取数据库的吞吐量和状态?
我已经遍历了Cosmos DB的文档,但是没有找到任何帮助。
I want to get the throughput value for all the databases present in the Cosmos DB.
答案 0 :(得分:0)
使用Python SDK时,可以使用request_charge来获取它,
Python SDK中的CosmosClient对象(请参阅此快速入门 关于其用法)公开了last_response_headers词典, 映射基础HTTP API返回的所有标头的最后一个 操作已执行。请求费用可在 x-ms-request-charge键。
response = client.ReadItem('dbs/database/colls/container/docs/itemId', { 'partitionKey': 'partitionKey' })
request_charge = client.last_response_headers['x-ms-request-charge']
答案 1 :(得分:0)
Python Azure SDK(> = 4.0.0)的示例
from azure.cosmos import CosmosClient
class AzureHelper(object):
def __init__(self, url, key):
self.url = url
self.key = key
self._client = None
self._keyspace = None
def connect(self):
self._client = CosmosClient(self.url, self.key)
def get_list_keyspaces(self):
result = []
for db in self._client.list_databases():
result.append(db['id'])
return result
def switch_keyspace(self, keyspace):
self._keyspace = self._client.get_database_client(keyspace)
def get_list_tables(self):
result = []
for table in self._keyspace.list_containers():
result.append(table['id'])
return result
def get_throughput(self, table):
container = self._keyspace.get_container_client(table)
offer = container.read_offer()
throughput = offer.properties['content']['offerThroughput']
return throughput
if __name__ == '__main__':
url = '<Cosmos DB URL, like https://testdb.cosmos.azure.com:443>'
key = '<Primary Password>'
az = AzureHelper(url, key)
az.connect()
for keyspace in az.get_list_keyspaces():
az.switch_keyspace(keyspace)
for table in az.get_list_tables():
throughput = az.get_throughput(table)
print(f'keyspace {keyspace}, table {table}, throughput {throughput}')