I am getting a summary of our log analytics workspaces in the company, this includes the tables that are being used in each workspace, as well as other data such as the ingestion volume.
The closest thing to "get" this is to use this command in PowerShell
Get-AzOperationalInsightsWorkspaceUsage -ResourceGroupName "RG_name" -Name "WS_name"
And it shows me this info:
Id : DataAnalyzed
CurrentValue : 0
Unit : Bytes
Limit : -1
NextResetTime : 7/24/2023 8:00:00 AM
QuotaPeriod : 1.00:00:00
Which is not enough, I am looking for this:
I searched for anything similar but didn’t find anything else. Hope there is a solution that I am missing.
2
Answers
You can get this using the REST API. The call you want to make is to Workspace Usages, which will show you your usage in bytes.
https://learn.microsoft.com/en-us/rest/api/loganalytics/workspace-usages/list?tabs=HTTP#workspacelistusagesresult
You can call REST API’s directly from powershell using
Invoke-RestMethod
. It is a twostep process. First, you need to make a REST call to authenticate, then you can make your subsequent REST calls using the token you received during the auth call. Steps are fully documented here (the example here shows how you can extract the token from Powershell Context):https://learn.microsoft.com/en-us/azure/governance/resource-graph/first-query-rest-api
Assuming you will be using your user account to query the Log Analytics Rest API and you have access to the Az Module plus Reader roles over the target Log Analytics Workspace, this is how you can get the ingestion volume by querying the
Usage
table.Up to this point in
$response
you would have the ingestion volume per table in your Log Analytics Workspace, problem is the response from this API is really bad so you have to enumerate the columns and rows to get objects out of it like so: