{"id":4777,"date":"2023-10-12T15:54:04","date_gmt":"2023-10-12T15:54:04","guid":{"rendered":"https:\/\/reviewnprep.com\/blog\/?p=4777"},"modified":"2023-10-12T00:56:28","modified_gmt":"2023-10-12T00:56:28","slug":"utilizing-kusto-query-language-kql-for-effective-azure-service-monitoring","status":"publish","type":"post","link":"https:\/\/reviewnprep.com\/blog\/utilizing-kusto-query-language-kql-for-effective-azure-service-monitoring\/","title":{"rendered":"Utilizing Kusto Query Language (KQL) for Effective Azure Service Monitoring"},"content":{"rendered":"\n<p>In today&#8217;s cloud-centric world, monitoring Azure services and resources is paramount for maintaining the health, performance, and security of your cloud infrastructure. Azure provides a wide array of monitoring and logging capabilities, and one powerful tool in your monitoring arsenal is the Kusto Query Language (KQL). <\/p>\n\n\n\n<p>In this blog, we&#8217;ll explore why KQL is essential for monitoring Azure services and resources and provide relevant code examples to help you get started.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_66_1 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69d5ec864db3e\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69d5ec864db3e\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/reviewnprep.com\/blog\/utilizing-kusto-query-language-kql-for-effective-azure-service-monitoring\/#Why_is_KQL_Needed_for_Azure_Monitoring\" title=\"Why is KQL Needed for Azure Monitoring?\">Why is KQL Needed for Azure Monitoring?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/reviewnprep.com\/blog\/utilizing-kusto-query-language-kql-for-effective-azure-service-monitoring\/#1_Centralized_Data_Access\" title=\"1. Centralized Data Access\">1. Centralized Data Access<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/reviewnprep.com\/blog\/utilizing-kusto-query-language-kql-for-effective-azure-service-monitoring\/#2_Real-time_Insights\" title=\"2. Real-time Insights\">2. Real-time Insights<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/reviewnprep.com\/blog\/utilizing-kusto-query-language-kql-for-effective-azure-service-monitoring\/#3_Customized_Analytics\" title=\"3. Customized Analytics\">3. Customized Analytics<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/reviewnprep.com\/blog\/utilizing-kusto-query-language-kql-for-effective-azure-service-monitoring\/#4_Unified_query_language\" title=\"4. Unified query language\">4. Unified query language<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/reviewnprep.com\/blog\/utilizing-kusto-query-language-kql-for-effective-azure-service-monitoring\/#Real_KQL_Examples\" title=\"Real KQL Examples\">Real KQL Examples<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/reviewnprep.com\/blog\/utilizing-kusto-query-language-kql-for-effective-azure-service-monitoring\/#Example_1_Querying_Azure_Activity_Logs\" title=\"Example 1: Querying Azure Activity Logs\">Example 1: Querying Azure Activity Logs<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/reviewnprep.com\/blog\/utilizing-kusto-query-language-kql-for-effective-azure-service-monitoring\/#Example_2_Analyzing_Azure_Metrics\" title=\"Example 2: Analyzing Azure Metrics\">Example 2: Analyzing Azure Metrics<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/reviewnprep.com\/blog\/utilizing-kusto-query-language-kql-for-effective-azure-service-monitoring\/#Example_3_Identifying_Security_Threats\" title=\"Example 3: Identifying Security Threats\">Example 3: Identifying Security Threats<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/reviewnprep.com\/blog\/utilizing-kusto-query-language-kql-for-effective-azure-service-monitoring\/#Example_4_Query_Application_Insights_data\" title=\"Example 4: Query Application Insights data\">Example 4: Query Application Insights data<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/reviewnprep.com\/blog\/utilizing-kusto-query-language-kql-for-effective-azure-service-monitoring\/#Example_5_Analyze_Azure_activity_logs\" title=\"Example 5: Analyze Azure activity logs\">Example 5: Analyze Azure activity logs<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/reviewnprep.com\/blog\/utilizing-kusto-query-language-kql-for-effective-azure-service-monitoring\/#Example_6_Monitor_VM_disk_usage_with_Log_Analytics\" title=\"Example 6: Monitor VM disk usage with Log Analytics\">Example 6: Monitor VM disk usage with Log Analytics<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/reviewnprep.com\/blog\/utilizing-kusto-query-language-kql-for-effective-azure-service-monitoring\/#Conclusion\" title=\"Conclusion\">Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_is_KQL_Needed_for_Azure_Monitoring\"><\/span>Why is KQL Needed for Azure Monitoring?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><a href=\"https:\/\/azure.com\" target=\"_blank\" rel=\"noreferrer noopener\">Azure<\/a> generates huge amounts of log and telemetry data across services and resources. This data holds valuable insights on the health and performance of your Azure environment. However, making sense of such large volumes of data is challenging. <\/p>\n\n\n\n<p>KQL provides a powerful and flexible query language that can be used to analyze and derive insights from the massive amounts of log and telemetry data in Azure. KQL is a read-only language, so you don\u2019t need to think about&nbsp;<strong>INSERT<\/strong>,&nbsp;<strong>DELETE<\/strong>,&nbsp;<strong>UPDATE<\/strong>&nbsp;and so on. <\/p>\n\n\n\n<p>Check out this example to show all Azure blobs<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#22272e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/ Show blob storage requests\nStorageBlobLogs\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F47067\">\/\/<\/span><span style=\"color: #ADBAC7\"> Show blob storage requests<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">StorageBlobLogs<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Pretty amazing, huh!&nbsp;<\/p>\n\n\n\n<p>Here are some key reasons why KQL is crucial for Azure monitoring:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Fast and scalable<\/strong>: KQL is designed for massive data volumes. Queries execute quickly over terabytes of data. This enables analyzing data in near real-time.<\/li>\n\n\n\n<li><strong>Powerful analytics<\/strong>: KQL includes abilities like aggregation, joins, ranking, and more that make analysis easier. You can get started with simple queries and evolve to build advanced analytics.<\/li>\n\n\n\n<li><strong>Customizable<\/strong>: KQL is customizable to augment built-in functionality with user-defined functions, custom aggregations, and more.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Centralized_Data_Access\"><\/span>1. Centralized Data Access<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Azure services generate an abundance of logs, metrics, and telemetry data. KQL provides a unified language to query this data, enabling you to access information from various sources in one place.<\/p>\n\n\n\n<p>KQL includes abilities like aggregation, joins, ranking, and more that make analysis easier. You can get started with simple queries and evolve to build advanced analytics.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Real-time_Insights\"><\/span>2. Real-time Insights<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>KQL allows you to perform real-time analysis on your Azure resources. You can quickly identify and respond to issues, making it an invaluable tool for maintaining system health.<\/p>\n\n\n\n<p>KQL is designed for massive data volumes. Queries execute quickly over terabytes of data. This enables analyzing data in near real-time.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Customized_Analytics\"><\/span>3. Customized Analytics<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>KQL is incredibly flexible. You can write custom queries to gain deep insights into your specific Azure resources and applications, tailoring your monitoring to your organization&#8217;s unique needs.<\/p>\n\n\n\n<p>KQL is customizable to augment built-in functionality with user-defined functions, custom aggregations, and more.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Unified_query_language\"><\/span>4. <strong>Unified query language<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Azure Monitor uses KQL as its query language, making it a seamless choice for monitoring Azure resources. KQL provides a common syntax and semantics that works across various Azure data sources like Log Analytics, Application Insights, etc.<\/p>\n\n\n\n<p>It&#8217;s tightly integrated with Azure services like Log Analytics, Application Insights, and Security Center. This avoids having to learn different query languages.<\/p>\n\n\n\n<p>Now that we understand why KQL is essential, let&#8217;s explore some practical examples of how to utilize it effectively for monitoring Azure services and resources.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Real_KQL_Examples\"><\/span>Real KQL Examples<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Important thing to note in KQL is the | (pipe) element. KQL queries use pipe as symbol to delineate each operation. Additionally the operations are executed in the order they are written. <\/p>\n\n\n\n<p>Simply put, the data set is manipulated at each step, and then the resulting set is \u201cpiped\u201d to the next step.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_1_Querying_Azure_Activity_Logs\"><\/span>Example 1: Querying Azure Activity Logs<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Azure Activity Logs record all operations performed on resources in your Azure subscription. You can use KQL to query these logs to track changes and audit activities. Here&#8217;s an example:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#22272e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"AzureActivity\n| where ResourceGroup == &quot;YourResourceGroup&quot; and OperationName == &quot;Microsoft.Compute\/virtualMachines\/delete&quot;\n| project Resource, Caller, ActivityStatus, ActivityDateTime\n| order by ActivityDateTime desc\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ADBAC7\">AzureActivity<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">| <\/span><span style=\"color: #F47067\">where<\/span><span style=\"color: #ADBAC7\"> ResourceGroup <\/span><span style=\"color: #F47067\">==<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #96D0FF\">&quot;YourResourceGroup&quot;<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #F47067\">and<\/span><span style=\"color: #ADBAC7\"> OperationName <\/span><span style=\"color: #F47067\">==<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #96D0FF\">&quot;Microsoft.Compute\/virtualMachines\/delete&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">| project <\/span><span style=\"color: #F47067\">Resource<\/span><span style=\"color: #ADBAC7\">, <\/span><span style=\"color: #F47067\">Caller<\/span><span style=\"color: #ADBAC7\">, ActivityStatus, ActivityDateTime<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">| <\/span><span style=\"color: #F47067\">order by<\/span><span style=\"color: #ADBAC7\"> ActivityDateTime <\/span><span style=\"color: #F47067\">desc<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This query retrieves information about deleted virtual machines in a specific resource group, including the user who initiated the operation and the timestamp.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_2_Analyzing_Azure_Metrics\"><\/span>Example 2: Analyzing Azure Metrics<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Azure Monitor Metrics provide data on the performance of your Azure resources. You can use KQL to analyze these metrics and create custom alerts. Here&#8217;s an example querying CPU usage for a virtual machine:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#22272e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Perf\n| where ObjectName == &quot;Processor&quot; and CounterName == &quot;% Processor Time&quot; and InstanceName == &quot;_Total&quot;\n| summarize avg(CounterValue) by bin(TimeGenerated, 1h), Computer\n| render timechart\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ADBAC7\">Perf<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">| <\/span><span style=\"color: #F47067\">where<\/span><span style=\"color: #ADBAC7\"> ObjectName <\/span><span style=\"color: #F47067\">==<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #96D0FF\">&quot;Processor&quot;<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #F47067\">and<\/span><span style=\"color: #ADBAC7\"> CounterName <\/span><span style=\"color: #F47067\">==<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #96D0FF\">&quot;% Processor Time&quot;<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #F47067\">and<\/span><span style=\"color: #ADBAC7\"> InstanceName <\/span><span style=\"color: #F47067\">==<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #96D0FF\">&quot;_Total&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">| summarize <\/span><span style=\"color: #6CB6FF\">avg<\/span><span style=\"color: #ADBAC7\">(CounterValue) <\/span><span style=\"color: #F47067\">by<\/span><span style=\"color: #ADBAC7\"> bin(TimeGenerated, 1h), Computer<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">| render timechart<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This query plots a time chart of the average CPU usage for all virtual machines in your environment over the last hour.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_3_Identifying_Security_Threats\"><\/span>Example 3: Identifying Security Threats<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Azure Security Center generates security alerts and recommendations. You can leverage KQL to investigate and respond to security threats. Here&#8217;s a simple query to find high-severity security alerts:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#22272e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"SecurityAlert\n| where Severity == &quot;High&quot;\n| project TimeGenerated, AlertName, ResourceName, ResourceGroup, Status\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ADBAC7\">SecurityAlert<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">| <\/span><span style=\"color: #F47067\">where<\/span><span style=\"color: #ADBAC7\"> Severity <\/span><span style=\"color: #F47067\">==<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #96D0FF\">&quot;High&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">| project TimeGenerated, AlertName, ResourceName, ResourceGroup, <\/span><span style=\"color: #F47067\">Status<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This query lists high-severity security alerts, along with relevant information like the resource name and alert status.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_4_Query_Application_Insights_data\"><\/span>Example 4: <strong>Query Application Insights data<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#22272e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"app('myApplication').requests\n| summarize requestCount=count(), durationAvg=avg(duration) by name\n| order by requestCount desc\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ADBAC7\">app(<\/span><span style=\"color: #96D0FF\">&#39;myApplication&#39;<\/span><span style=\"color: #ADBAC7\">).requests<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">| summarize requestCount<\/span><span style=\"color: #F47067\">=<\/span><span style=\"color: #6CB6FF\">count<\/span><span style=\"color: #ADBAC7\">(), durationAvg<\/span><span style=\"color: #F47067\">=<\/span><span style=\"color: #6CB6FF\">avg<\/span><span style=\"color: #ADBAC7\">(duration) <\/span><span style=\"color: #F47067\">by<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #F47067\">name<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">| <\/span><span style=\"color: #F47067\">order by<\/span><span style=\"color: #ADBAC7\"> requestCount <\/span><span style=\"color: #F47067\">desc<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This query fetches HTTP request data from an Application Insights application, calculates the count and average duration for each request name and sorts the results by highest count.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_5_Analyze_Azure_activity_logs\"><\/span>Example 5: Analyze Azure activity logs<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#22272e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"AzureActivity | \nwhere OperationName == &quot;Restart Virtual Machine&quot; | \nsummarize count() by ResourceGroup, VirtualMachineName\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ADBAC7\">AzureActivity | <\/span><\/span>\n<span class=\"line\"><span style=\"color: #F47067\">where<\/span><span style=\"color: #ADBAC7\"> OperationName <\/span><span style=\"color: #F47067\">==<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #96D0FF\">&quot;Restart Virtual Machine&quot;<\/span><span style=\"color: #ADBAC7\"> | <\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">summarize <\/span><span style=\"color: #6CB6FF\">count<\/span><span style=\"color: #ADBAC7\">() <\/span><span style=\"color: #F47067\">by<\/span><span style=\"color: #ADBAC7\"> ResourceGroup, VirtualMachineName<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This query processes Azure activity logs, filters log rows for virtual machine restart operations, and summarizes restart counts by resource group and VM.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_6_Monitor_VM_disk_usage_with_Log_Analytics\"><\/span>Example 6: Monitor VM disk usage with Log Analytics<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#22272e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Perf \n| where ObjectName == &quot;Logical Disk&quot; and CounterName == &quot;Free Megabytes&quot; \n| summarize avg(CounterValue) by Computer, _ResourceId\n| extend Disk_Used = 10000 - avg_CounterValue\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ADBAC7\">Perf <\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">| <\/span><span style=\"color: #F47067\">where<\/span><span style=\"color: #ADBAC7\"> ObjectName <\/span><span style=\"color: #F47067\">==<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #96D0FF\">&quot;Logical Disk&quot;<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #F47067\">and<\/span><span style=\"color: #ADBAC7\"> CounterName <\/span><span style=\"color: #F47067\">==<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #96D0FF\">&quot;Free Megabytes&quot;<\/span><span style=\"color: #ADBAC7\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">| summarize <\/span><span style=\"color: #6CB6FF\">avg<\/span><span style=\"color: #ADBAC7\">(CounterValue) <\/span><span style=\"color: #F47067\">by<\/span><span style=\"color: #ADBAC7\"> Computer, _ResourceId<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">| extend Disk_Used <\/span><span style=\"color: #F47067\">=<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #6CB6FF\">10000<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #F47067\">-<\/span><span style=\"color: #ADBAC7\"> avg_CounterValue<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This query calculates average free disk space from Perf table in Log Analytics workspace and derives used disk space.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Kusto Query Language (KQL) is an indispensable tool for monitoring Azure services and resources effectively. Whether you&#8217;re analyzing activity logs, performance metrics, or security alerts, KQL&#8217;s flexibility and power make it a go-to choice for gaining insights and maintaining the health and security of your Azure environment. <\/p>\n\n\n\n<p>Start using KQL today to unlock the full potential of your Azure monitoring capabilities.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Further Reading: <\/p>\n\n\n\n<p><a href=\"https:\/\/reviewnprep.com\/blog\/automating-cloud-computing-tasks-with-ansible-simplifying-infrastructure-management\/\" target=\"_blank\" rel=\"noreferrer noopener\">Automating Cloud Computing Tasks with Ansible: Simplifying Infrastructure Management.<\/a>\u00a0<\/p>\n\n\n\n<p><a href=\"https:\/\/reviewnprep.com\/blog\/full-stack-developer-vs-software-engineer-unraveling-the-distinctions\/\" target=\"_blank\" rel=\"noreferrer noopener\">Discover the key differences between a Full-Stack Developer and a Software Engineer in this blog.<\/a><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to harness the power of KQL for efficient Azure service monitoring. Gain real-time insights and customized analytics. Dive in now!<\/p>\n","protected":false},"author":1,"featured_media":4780,"comment_status":"open","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,321,318],"tags":[32,14,13,372],"class_list":["post-4777","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure","category-data","category-database","tag-azure","tag-cloud","tag-devops","tag-kql"],"_links":{"self":[{"href":"https:\/\/reviewnprep.com\/blog\/wp-json\/wp\/v2\/posts\/4777"}],"collection":[{"href":"https:\/\/reviewnprep.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/reviewnprep.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/reviewnprep.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/reviewnprep.com\/blog\/wp-json\/wp\/v2\/comments?post=4777"}],"version-history":[{"count":4,"href":"https:\/\/reviewnprep.com\/blog\/wp-json\/wp\/v2\/posts\/4777\/revisions"}],"predecessor-version":[{"id":4782,"href":"https:\/\/reviewnprep.com\/blog\/wp-json\/wp\/v2\/posts\/4777\/revisions\/4782"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/reviewnprep.com\/blog\/wp-json\/wp\/v2\/media\/4780"}],"wp:attachment":[{"href":"https:\/\/reviewnprep.com\/blog\/wp-json\/wp\/v2\/media?parent=4777"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/reviewnprep.com\/blog\/wp-json\/wp\/v2\/categories?post=4777"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/reviewnprep.com\/blog\/wp-json\/wp\/v2\/tags?post=4777"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}