Azure Cosmos DB 中的Diagnostic logging 使您能够执行此监控,以监控访问数据库的方式和时间。
请点击左侧导航中的Diagnostic logs,然后在您的azure cosmos db中点击Turn on diagnostics。
您可以将日志文件存储在azure account,流到eventhub或发送到azure analytics
从进行 Azure Cosmos DB 操作时起,您的帐户 two hours 中就可以使用日志。您可以自行管理存储帐户中的日志。
单个 blob 存储为文本,格式为 JSON blob。
{
"records":
[
{
"time": "Fri, 23 Jun 2017 19:29:50.266 GMT",
"resourceId": "contosocosmosdb",
"category": "DataPlaneRequests",
"operationName": "Query",
"resourceType": "Database",
"properties": {"activityId": "05fcf607-6f64-48fe-81a5-f13ac13dd1eb",`
"userAgent": "documentdb-dotnet-sdk/1.12.0 Host/64-bit MicrosoftWindowsNT/6.2.9200.0 AzureSearchIndexer/1.0.0",`
"resourceType": "Database","statusCode": "200","documentResourceId": "",`
"clientIpAddress": "13.92.241.0","requestCharge": "2.260","collectionRid": "",`
"duration": "9250","requestLength": "72","responseLength": "209", "resourceTokenUserRid": ""}
}
]
}
更多详情请参考here。
更新答案:
据我观察,Azure Cosmos DB 中的日志并没有使用Master key 或Resource Token 区分请求。
不过,我想为您提供一个解决方法。
你知道,Python Document DB SDK 实际上是REST API。
因此,您可以通过reverse proxy 将您的HTTP 请求发送到Azure 服务器,例如Nginx。
您可以通过请求URL的格式来判断是哪种访问方式,并记录在reverse proxy层中。
希望对你有帮助。