Forum Discussion
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
- funclicheCopper Contributor
thanks much! I'll give it a try
- LeonPavesicSilver 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:
- Azure Monitor Log Analytics documentation: https://learn.microsoft.com/en-us/azure/azure-monitor/
- Azure Monitor Log Analytics KQL reference: https://learn.microsoft.com/en-us/azure/azure-monitor/logs/log-query-overview
- Tutorial: Monitor published APIs in Azure API Management: https://learn.microsoft.com/en-us/azure/api-management/api-management-howto-use-azure-monitor
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic
(LinkedIn)