Azure offers a variety of built-in log queries that can be accessed via Azure Monitor and Log Analytics. These queries are predefined to help users quickly gain insights from their Azure resources and services. Built-in queries typically focus on common use cases such as monitoring infrastructure, security, performance, and diagnostics. Here’s an overview of key built-in log queries in Azure:
Activity Log Queries
These queries are used to access the Azure Activity Log, which records all management events in Azure, such as resource creation, modification, and deletion.
Failed Login Attempts:
xxxxxxxxxx41AzureActivity2| where ActivityStatus == "Failure" and OperationName == "Sign-in"3| project TimeGenerated, Caller, OperationName, ActivityStatus, Resource, ResourceGroup4| order by TimeGenerated descResource Deletions:
xxxxxxxxxx41AzureActivity2| where OperationName == "Delete Resource"3| project TimeGenerated, Resource, ResourceGroup, Caller4| order by TimeGenerated descSecurity Log Queries
Azure Sentinel provides built-in queries that can help monitor and detect security-related events. These queries are often used to detect suspicious behavior, such as unauthorized access or potential threats.
Failed Sign-ins (Security):
xxxxxxxxxx41SecurityEvent2| where EventID == 4625 // Failed logon3| project TimeGenerated, Account, IPAddress, WorkstationName, FailureReason4| order by TimeGenerated descUnusual User Activity:
xxxxxxxxxx41SecurityEvent2| where EventID == 4624 // Logon event3| summarize Count = count() by Account, bin(TimeGenerated, 1h)4| order by Count descSuspicious PowerShell Commands:
xxxxxxxxxx41SecurityEvent2| where EventID == 4104 // PowerShell command3| where Message contains "Invoke-Expression"4| project TimeGenerated, Account, MessagePerformance Log Queries
These queries monitor the performance of virtual machines, applications, and other resources in your Azure environment.
CPU Utilization on Virtual Machines:
xxxxxxxxxx51Perf2| where ObjectName == "Processor" and CounterName == "% Processor Time"3| where Computer startswith "VM" // Filtering for VMs4| summarize avg(CounterValue) by Computer, bin(TimeGenerated, 5m)5| order by TimeGenerated descMemory Usage on Virtual Machines:
xxxxxxxxxx51Perf2| where ObjectName == "Memory" and CounterName == "Available MBytes"3| where Computer startswith "VM" // Filter for VMs4| summarize avg(CounterValue) by Computer, bin(TimeGenerated, 10m)5| order by TimeGenerated descDisk I/O Performance:
xxxxxxxxxx41Perf2| where ObjectName == "LogicalDisk" and CounterName == "Disk Write Bytes/sec"3| summarize avg(CounterValue) by Computer, bin(TimeGenerated, 5m)4| order by TimeGenerated descAzure Resource Usage Queries
These queries focus on the usage metrics of various Azure resources, like storage accounts, networking, etc.
Storage Account Activity:
xxxxxxxxxx41AzureDiagnostics2| where ResourceType == "STORAGEACCOUNTS" and Resource == "myStorageAccount"3| summarize count() by bin(TimeGenerated, 1h)4| order by TimeGenerated descAzure Network Traffic:
xxxxxxxxxx41AzureDiagnostics2| where ResourceType == "NETWORK" and OperationName == "NetworkSecurityGroupFlowEvent"3| summarize Count = count() by SourceIP, DestinationIP, bin(TimeGenerated, 1h)4| order by TimeGenerated descApplication Insights Queries
Built-in queries are also available for analyzing application performance, traces, and requests for applications monitored by Application Insights.
Request Failure Rate:
xxxxxxxxxx41requests2| where success == "False"3| summarize Count = count() by bin(timestamp, 1h), name4| order by Count descTop Exceptions by Count:
xxxxxxxxxx31exceptions2| summarize Count = count() by type, bin(timestamp, 1h)3| order by Count descSlowest Requests:
xxxxxxxxxx41requests2| where duration > 1000 // Requests taking longer than 1 second3| project timestamp, name, duration4| order by duration descAzure Kubernetes Service (AKS) Logs
For Azure Kubernetes Service (AKS), there are built-in queries to monitor Kubernetes clusters and containers.
AKS Cluster Health:
xxxxxxxxxx51ContainerLog2| where ClusterName == "myAKSCluster"3| where LogEntry contains "error"4| project TimeGenerated, LogEntry5| order by TimeGenerated descPod Restarts:
xxxxxxxxxx41KubePodInventory2| where ClusterName == "myAKSCluster"3| summarize Restarts = sum(RestartCount) by PodName, bin(TimeGenerated, 1h)4| order by Restarts descAzure Firewall Logs
For monitoring Azure Firewall and network security, there are queries that help track activity logs, traffic analytics, and other key metrics.
Firewall Drop Log:
xxxxxxxxxx41AzureDiagnostics2| where ResourceType == "AZUREFIREWALL" and Action_s == "Deny"3| summarize count() by SourceIP_s, DestinationIP_s, bin(TimeGenerated, 1h)4| order by TimeGenerated descFirewall Allowed Traffic:
xxxxxxxxxx41AzureDiagnostics2| where ResourceType == "AZUREFIREWALL" and Action_s == "Allow"3| summarize count() by SourceIP_s, DestinationIP_s, bin(TimeGenerated, 1h)4| order by TimeGenerated descAlert and Diagnostic Queries
Built-in diagnostic queries help you view alerts triggered by various Azure services.
Active Alerts:
xxxxxxxxxx51Alerts2| where Severity == "Critical" or Severity == "Warning"3| where State == "Active"4| project TimeGenerated, AlertName, Severity, Resource5| order by TimeGenerated descTriggered Alerts for Resource:
xxxxxxxxxx41Alerts2| where Resource == "myResource"3| project TimeGenerated, AlertName, Severity, State4| order by TimeGenerated descCustom Logs and Application Data Queries
Custom queries can be used to search custom log data that you have configured in Log Analytics.
Custom Log Search:
xxxxxxxxxx41CustomLogs_CL2| where LogLevel == "Error"3| project TimeGenerated, Message, LogLevel4| order by TimeGenerated descHow to Use Built-in Queries
To use built-in queries:
Go to Azure Portal.
Navigate to Azure Monitor or Log Analytics.
Select Logs.
In the query window, you’ll find the "Built-in" queries under the "Query Explorer" section.
Click on the desired query to run it, or modify it to fit your needs.
Summary
These built-in queries are a great starting point for common monitoring, performance, security, and diagnostic tasks in Azure. You can adapt and expand on them based on your specific use cases.




















Leave a Reply