Coal Chris
Coal Chris

Reputation: 31

How to get average QuotaResources values over time from Azure Resource Graph?

I want to get historical data on my Azure subscriptions' CPU core quota usage, so that I can get the average usage over a time span (e.g. 1 month). The current usage can be retrieved by following Azure Quota's documentation on querying Azure Resource Graph (ARG).

Example Query:

QuotaResources
| where type =~ 'microsoft.compute/locations/usages'
| where isnotempty(properties)
| mv-expand propertyJson = properties.value limit 400
| extend
    Usage = propertyJson.currentValue,
    Quota = propertyJson.['limit'],
    SKUName = tostring(propertyJson.['name'].value)
| where Usage > 0
| where SKUName startswith "standard" and SKUName endswith "family"
| project subscriptionId, SKUName, Quota, Usage
| extend UsagePercentage=(100 * Usage / Quota)

However, there is no field for date / time in the results. It only provides the current usage.

How can I get the historical subscription usage? Ideally with data points at intervals of 24 hours or less.

A potential solution is to periodically query ARG and append the results to a database table.

I attempted to use Log Analytics Search Job to query and store the ARG data. Search Job can successfully do this task for regular Log Analytics tables, but it returned an error when querying against ARG.

validation error: 
HttpClient: Response status code does not indicate success - 400 (Bad Request), for request - /v1/workspaces/<workspace ID>/search/schema?editMode=true&isSummarized=false, due to reason - [User-defined functions are not supported, start position: 0, end position: 3].

Another alternative is to create a logic app which periodically runs a script with custom logic to query ARG and push the results to a Log Analytics workspace. E.g. Similar to this question/solution.

Upvotes: 0

Views: 123

Answers (0)

Related Questions