<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Kusto on Ash Tewari</title><link>https://www.tewari.info/tag/kusto/</link><description>Recent content in Kusto on Ash Tewari</description><generator>Hugo -- gohugo.io</generator><language>en-US</language><lastBuildDate>Sun, 25 Apr 2021 19:40:55 +0000</lastBuildDate><atom:link href="https://www.tewari.info/tag/kusto/feed.xml" rel="self" type="application/rss+xml"/><item><title>Kusto Queries on AKS Clusters</title><link>https://www.tewari.info/2021/04/25/kusto-queries-on-aks-clusters/</link><pubDate>Sun, 25 Apr 2021 19:40:55 +0000</pubDate><guid>https://www.tewari.info/2021/04/25/kusto-queries-on-aks-clusters/</guid><description>&lt;p&gt;&lt;a class="link" href="https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/" target="_blank" rel="noopener"&#10; &gt;Kusto&lt;/a&gt; query language can be used to get &lt;a class="link" href="https://docs.microsoft.com/en-us/azure/azure-monitor/containers/container-insights-log-search" target="_blank" rel="noopener"&#10; &gt;insights&lt;/a&gt; into Azure Kubernetes Service (&lt;a class="link" href="https://azure.microsoft.com/en-us/services/kubernetes-service/" target="_blank" rel="noopener"&#10; &gt;AKS&lt;/a&gt;) clusters. &lt;a class="link" href="https://docs.microsoft.com/en-us/azure/azure-monitor/containers/container-insights-overview" target="_blank" rel="noopener"&#10; &gt;Container insights&lt;/a&gt; collects data from AKS clusters and forwards it to &lt;a class="link" href="https://docs.microsoft.com/en-us/azure/azure-monitor/logs/log-analytics-tutorial" target="_blank" rel="noopener"&#10; &gt;Log Analytics&lt;/a&gt; workspace, if enabled for a cluster. This data is available for querying in the &lt;a class="link" href="https://docs.microsoft.com/en-us/azure/azure-monitor/logs/data-platform-logs" target="_blank" rel="noopener"&#10; &gt;Azure Monitor&lt;/a&gt;. Here is an example of how you can query the pods not in running state in specific namespaces.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;KubePodInventory&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;| where Namespace in (&amp;#34;dv&amp;#34;,&amp;#34;test&amp;#34;,&amp;#34;prod&amp;#34;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;| where ContainerStatus != &amp;#34;Running&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;| where ContainerStatusReason !in (&amp;#34;&amp;#34;, &amp;#34;Completed&amp;#34;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;| distinct Namespace, Name&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-7.png"&#10;&#9;&#9;&#9;alt="Log Analytics query results listing pods not in running state by namespace"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;p&gt;The following query includes the name of the AKS cluster and renders the output as a stacked bar chart.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;KubePodInventory&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;| where Namespace in (&amp;#34;dv&amp;#34;,&amp;#34;test&amp;#34;,&amp;#34;prod&amp;#34;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;| where ContainerStatus != &amp;#34;Running&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;| where ContainerStatusReason !in (&amp;#34;&amp;#34;, &amp;#34;Completed&amp;#34;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;| distinct ClusterName, Namespace, Name&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;| summarize dcount(Name) by ClusterName, Namespace&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;| render columnchart kind=stacked100&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-8-1024x582.png"&#10;&#9;&#9;&#9;alt="Stacked column chart of non-running pods by AKS cluster and namespace"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;p&gt;You can include multiple AKS clusters in the scope in which this query is executed by clicking on [Select scope] hyperlink.&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-12.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-15.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;p&gt;Create an Azure Dashboard panel with this output by clicking on [Pin to dashboard] button.&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-13.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-11-1024x676.png"&#10;&#9;&#9;&#9;alt="Azure dashboard showing the pinned AKS pod status chart"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;p&gt;You can also execute this Kusto query directly using powershell.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$workspaceName = &amp;#34;DefaultWorkspace-6637b095-xxxx-xxxx-xxxx-xxxxxxxxxxx-EUS&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$workspaceRG = &amp;#34;defaultresourcegroup-eus&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$WorkspaceID = (Get-AzOperationalInsightsWorkspace -Name $workspaceName -ResourceGroupName $workspaceRG).CustomerID&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$query = &amp;#39;KubePodInventory | where Namespace in (&amp;#34;dv&amp;#34;,&amp;#34;test&amp;#34;,&amp;#34;prod&amp;#34;) | where ContainerStatus != &amp;#34;Running&amp;#34; | where ContainerStatusReason !in (&amp;#34;&amp;#34;, &amp;#34;Completed&amp;#34;) | distinct ClusterName, Namespace, Name | summarize dcount(Name) by ClusterName, Namespace&amp;#39;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$result = Invoke-AzOperationalInsightsQuery -WorkspaceId $WorkspaceID -Query $query -Timespan (New-TimeSpan -days 1)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$result.results&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This allows you to include the results of your custom Kusto queries in any reports you might run using Azure Automation Runbooks.&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-14-1024x392.png"&#10;&#9;&#9;&#9;alt="PowerShell session running the Kusto query with Invoke-AzOperationalInsightsQuery"&gt;&#10;&lt;/figure&gt;&#10;&#10;</description></item></channel></rss>