在Azure Cosmos DB中查找mastekey访问的访问日志的位置

时间:2017-10-06 14:27:22

标签: python python-2.7 azure azure-cosmosdb azure-log-analytics

是否可以帮助我了解在哪里可以使用masterkey查找所有活动的日志以访问CosmosDB / DocumentDB azure。

背景: 我在日志中找到的只是用户ID,他在azure上访问了文档db。我们还使用Pydocumentdb在python中使用了一个脚本,它使用masterkey来访问Azure Cosmos DB中的数据。但是在日志中都看不到它。

由于

1 个答案:

答案 0 :(得分:1)

Azure Cosmos DB中的

Diagnostic logging使您可以执行此监视访问数据库的方式和时间。

请点击左侧导航栏中的Diagnostic logs,然后点击蔚蓝宇宙数据库中的Turn on diagnostics

enter image description here

您可以将日志文件存储在azure account中,流式传输到eventhub或发送到azure analytics

enter image description here

从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 keyResource Token的请求。

但是,我想为您提供一种解决方法。

您知道,Python Document DB SDK实际上是REST API

因此,您可以通过reverse proxy将您的HTTP请求发送到azure服务器,例如Nginx

您可以通过请求网址的格式判断哪种访问方式,并将其记录在reverse proxy图层中。

希望它对你有所帮助。