Forum Discussion

funcliche's avatar
funcliche
Copper Contributor
Oct 11, 2023

Log Analytics / Azure Monitor query to get API response times within AKS cluster

I am trying to run a query to get API response times (http APIs) where all these APIs are running in a single cluster. For example, I have API-A and API-B in a AKS cluster, I would like to know the http request times between these 2 APIs.

2 Replies

  • LeonPavesic's avatar
    LeonPavesic
    Silver Contributor

    Hi funcliche,

    To get API response times within an AKS cluster, you can use the following Log Analytics / Azure Monitor query:

     

     

    AzureDiagnostics
    | where Category == "kube-apiserver"
    | where (OperationName == "POST" or OperationName == "PUT")
    | where RequestURI contains "/api/"
    | project TimeGenerated, RequestURI, HttpStatusCode, ResponseTime
    | where HttpStatusCode == 200
    | summarize avg(ResponseTime) by RequestURIThis query will return a list of all API requests that were made to the Kubernetes API server, along with the average response time for each request.<br /><br />You can filter the results by the specific APIs that you are interested in by adding a where clause to the query. For example, to only include requests to API-A and API-B, you would add the following clause to the query:where RequestURI contains "/api/a/" or RequestURI contains "/api/b/" 

     

    You can also filter the results by time range by adding a where clause to the query. For example, to only include requests that were made in the past hour, you would add the following clause to the query:

     

     

    where TimeGenerated between (ago(1h)..now())Once you have run the query, you can view the results in the Azure Monitor Log Analytics portal. The results will be displayed in a table, with one row for each API request.<br /><br />

     

    Here are some useful links to:

     

     

Resources