在哪里可以找到Azure Cosmos数据库中mastekey访问的访问日志

2024-06-09 08:54:18 发布

您现在位置:Python中文网/ 问答频道 /正文

你能帮我理解在哪里可以找到使用主密钥访问CosmosDB/DocumentDB azure的所有活动的日志吗。在

背景: 我在日志中只能找到访问azure上文档数据库的userid。我们还使用Pydocumentdb编写了一个python脚本,它使用masterkey从azurecosmos数据库访问数据。但在日志中都看不到。在

谢谢


Tags: 数据文档脚本数据库密钥azure背景userid
1条回答
网友
1楼 · 发布于 2024-06-09 08:54:18

Azure Cosmos DB中的Diagnostic logging使您能够执行此监视,以如何以及何时访问数据库。在

请单击左侧导航中的Diagnostic logs,然后单击azure cosmos数据库中的Turn on diagnostics。在

enter image description here

您可以将日志文件存储在azure account、流到eventhub或发送到azure analytics

enter image description here

从Azure Cosmos DB操作开始,您的帐户two hours中就提供了日志。由您来管理存储帐户中的日志。在

单个blob存储为文本,格式为JSONblob。在

{
    "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中的更多详细信息。在

更新答案:

根据我的观察,azurecosmosdb中的日志不通过使用Master key或{}来区分请求。在

不过,我想为您提供一个解决办法。在

你知道,Python Document DB SDK实际上是REST API。在

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

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

希望对你有帮助。在

相关问题 更多 >