How to get metrics data of multiple resources(Container Apps) in one batch request?

tejas.talekar 0 Reputation points
2024-08-14T11:23:02.07+00:00

Hello,

We're looking to find a solution for Azure monitoring.

  1. We want to get the metrics data for a group of container apps filtered based on a tag
  2. The aggregated value of each metric, i.e., Number of requests, and billed duration
  3. How can we get the value of total billed duration metrics as it doesn't seem to be available in the Standard metrics? We do have HTTP ingress enabled for the container app.

Please note:

  • We do have Logs analytics workspace enabled, however, we are not ingesting the metrics data to the workspace.
  • Is there a way to do this without a workspace?

We've tried.

  • Metrics.list API -> This lists data for specific ResourceURI. However, it doesn't support getting data for multiple ResourceUris
  • tried @azure/arm-monitor npm library
  • Tried @azure/monitor-query

Looking forward to your support.

Thanks,
Tejas.

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,320 questions
Azure Container Apps
Azure Container Apps
An Azure service that provides a general-purpose, serverless container platform.
444 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Vinodh247 23,346 Reputation points MVP
    2024-09-17T12:24:18.6566667+00:00

    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:

    1. Query Resources by Tag using Resource Graph: Use the Azure Resource Graph API to filter the container apps by the desired tag.
    2. 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 the number 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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.