Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Azure log query from the command line with Azure CLI (az monitor)

I am trying to get the Azure log query data from the CLI because we want to get the log message automatically. For example, when we want to get exceptions message, we will got to Azure log and run the query like this

1

However, in powershell, when I run az monitor log-analytics query -w 0000000000000 --analytics-query "exceptions" (000 is the workspace ID)
then I got an error message BadArgumentError: The request had some invalid properties. But I did not get the error message when I use Azure Dashboard.

How would I modify my query? Or should I use a different function?

Thanks in advance

like image 459
Eclec Avatar asked Dec 20 '25 17:12

Eclec


1 Answers

After looking at your query I see you are merging two services(i.e., Log Analytics and Application Insights). You are using log analytics command for Application insights query. Instead, you can use the below command for errors and exceptions in your Log Analytics logs.

FunctionAppLogs 
| where TimeGenerated > ago(1h)
| where Level == "Warning" or Level == "Error"
| summarize count_per_app = count() by _ResourceId
| sort by count_per_app desc 
| render columnchart

You can use the below CLI Command as an example:

az monitor log-analytics query -w XXXXX --analytics-query "FunctionAppLogs | where TimeGenerated > ago(1h)| where Level == 'Warning' or Level == 'Error'| summarize count_per_app = count() by _ResourceId| sort by count_per_app desc | render columnchart"

Output:

enter image description here

like image 175
RithwikBojja Avatar answered Dec 23 '25 10:12

RithwikBojja



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!