Hi tejas.talekar,
Thanks for reaching out to Microsoft Q&A.
If avoiding Log Analytics Workspace, the best approach is likely to:
- Query the resources by tag with Azure Resource Graph.
- Fetch metrics in parallel with
Metrics.list
API. - Consider the Azure Cost Management API for tracking billed duration.
Using a workspace would simplify the aggregation, though it adds operational complexity and cost.
Explore the following options, I am sure one of it would help:
- The
Metrics.list
API does not directly support batch requests for multiple resource URIs, but you can script the process to loop over your resources and retrieve the metrics in parallel or sequence.- You can use Azure Resource Graph to query resources by their tags first, then fetch the metric data individually.
Steps:
- Query Resources by Tag using Resource Graph: Use the Azure Resource Graph API to filter the container apps by the desired tag.
- Fetch Metrics Data for Each Container App: For each resource URI obtained in step 1, you can use the
Metrics.list
API to fetch the metrics for each container app. You may parallelize the requests for efficiency.
This fetches the resource URIs of the container apps filtered by tags. You can then pass the resulting URIs to the Metrics.list
API.
az graph query -q "Resources | where type == 'Microsoft.Web/containerApps' | where tags.['<tag-key>'] == '<tag-value>'" --query "[].id"
- Though you are not currently ingesting metrics into a Log Analytics workspace, using a workspace will make querying and aggregation much simpler. You can ingest your container app metrics into the workspace, and then use KQLto perform aggregations like summing the
billed duration
or counting thenumber of requests
across multiple container apps. Even if you're avoiding a workspace for cost or complexity reasons, it might be worth revisiting this option for scalability, as custom aggregation like billed duration might not be available in the default metrics. - You can use ARM API to list multiple resources, get metrics for each resource, and then aggregate results in your code. ARM provides access to metrics data across different resources, although it would require iterating over individual resource URIs. But I am not sure on this option, you need to explore.
- Since the billed duration metric might not be readily available through the default
Metrics.list
API, you could use the Azure Cost Management API to track the billing aspect of your container apps. The billed duration is more of a cost-related metric rather than a direct performance metric, so integrating with the cost API might give you better visibility.
Please 'Upvote'(Thumbs-up) and 'Accept' as an answer if the reply was helpful. This will benefit other community members who face the same issue.