skip to Main Content

Is it possible to write a Kusto query for memory/CPU usage as percent of max for an Azure Container App? In the table AppPerformanceCounters I can find data on the Private Bytes and % Processor Time. But this does not seem to be what I need.

This was possible with AKS using the table Perf, which contains information such as memoryLimitBytes, cpuLimitNanoCores etc.

2

Answers


  1. Chosen as BEST ANSWER

    This is the answer that I got from the Microsoft support:

    Hello, you cannot directly divide the metrics by total available resources in the “Metrics” tab, you can still perform calculations outside of Azure. You can write a kusto queries for instance:

    Perf
    | where ObjectName == "Container" and CounterName == "UsageNanoCores"
    | summarize AvgCpuUsage = avg(CounterValue) by bin(TimeGenerated, 1h)
    | project TimeGenerated, CpuUtilizationPercentage = AvgCpuUsage / <maximum_cpu_capacity_in_nanocores> * 100
    

    Or

    Perf
    | where ObjectName == "Container" and CounterName == "WorkingSetBytes"
    | summarize AvgMemoryUsage = avg(CounterValue) by bin(TimeGenerated, 1h)
    | project TimeGenerated, MemoryUtilizationPercentage = AvgMemoryUsage / <total_available_memory_in_bytes> * 100
    

    Unfortunately, you cannot directly run Kusto queries like the one provided inside Azure Container Apps (ACA). The query you’ve written is valid Kusto Query Language (KQL), but it is typically executed in an Azure Monitor context (such as Azure Data Explorer or Log Analytics). Which means Azure Container App is needs to configure to send telemetry data (logs and metrics) to Azure Monitor so that you can run the above commands.

    I eventually found that I had already sent some data from the Container App to Log Analytics. In there I was able to go into "Live Metrics", where I could see CPU usage % (for the process) and current memory usage of my application. From there I was able to generate the following two queries which show exactly that:

    // committedMemoryFriendlyName
    performanceCounters
    | where timestamp >= ago(24h) and name == "Private Bytes"
    | where cloud_RoleInstance contains "XXX"
    | summarize ['performanceCounters_avg_value'] = avg(value) by bin(timestamp, 30min)
    | render timechart
    
    // regularAppCpuTitle
    performanceCounters
    | where timestamp >= ago(24h)
    | where name == "% Processor Time"
    | where cloud_RoleInstance contains "XXX"
    | summarize ['performanceCounters_avg_value'] = avg(value) by bin(timestamp, 30min)
    | render timechart
    

    So these graphs are not technically the CPU and Memory of the entire container app, but rather for the single application running in the container app. So it should be a fairly decent estimate.


  2. If you’re looking specifically for metrics related to memory and CPU usage for Azure Container Apps, you can use the metrics explorer to investigate them, but apparently it is not supported to export these metrics to Log Analytics Workspace and perform queries there.

    In LAW, you can access the app’s system and app logs indeed – https://learn.microsoft.com/en-us/azure/container-apps/log-monitoring?tabs=bash

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search