我正在获取公司日志分析工作区的摘要,其中包括每个工作区中使用的表,以及其他数据,如摄入量。
最接近“get”this的方法是在PowerShell中使用此命令
Get-AzOperationalInsightsWorkspaceUsage -ResourceGroupName "RG_name" -Name "WS_name"
字符串
它显示了这个信息:
Id : DataAnalyzed
CurrentValue : 0
Unit : Bytes
Limit : -1
NextResetTime : 7/24/2023 8:00:00 AM
QuotaPeriod : 1.00:00:00
型
这是不够的,我正在寻找这个:
的数据
我搜索了类似的东西,但没有找到其他东西。希望有一个解决方案,我错过了。
2条答案
按热度按时间voase2hg1#
假设您将使用您的用户帐户查询Log Analytics Rest API,并且您可以访问目标日志分析工作区**上的Az Module**和Reader角色,这就是您通过查询
Usage
table获取摄取量的方法。字符串
到目前为止,在
$response
中,您将在日志分析工作区中获得每个表的摄取量,问题是此API的响应非常糟糕,因此您必须枚举列和行以从中获取对象,如下所示:型
如果使用Service Principal而不是模拟我们的用户帐户,逻辑几乎相同,唯一的变化是我们获取令牌的方式:
型
pbwdgjma2#
你可以使用REST API来实现。您要调用的是Workspace Usages,它会以字节为单位显示您的使用情况。
https://learn.microsoft.com/en-us/rest/api/loganalytics/workspace-usages/list?tabs=HTTP#workspacelistusagesresult
您可以使用
Invoke-RestMethod
直接从powershell调用REST API。这是一个两步的过程。首先,您需要进行REST调用以进行身份验证,然后您可以使用在auth调用期间收到的令牌进行后续的REST调用。步骤在这里有完整的文档(这里的示例显示了如何从Powershell Context中提取令牌):https://learn.microsoft.com/en-us/azure/governance/resource-graph/first-query-rest-api