How to use Application Insights to get the most requested pages in a website

by Patrick Lee on 30 Apr 2022 in categories tech with tags Application Insights Azure dashboard kusto SQL

Microsoft's Application Insights is very useful for supporting customers / tracking errors etc. 

It uses the kusto querying language, which is subtly different to SQL so it takes a bit of getting used to in order to get the queries you want.  (NB you might find this 

Kusto to SQL cheatsheet useful).

Kusto query to get top items in descending order

Here is a very easy way to get a table (or chart, but the urls are hard to see in the chart because they are too long for a chart axis marker) of the top requests made to a website using kusto:

requests 
| summarize count() by url
| order by count_

You can filter the requests, e.g. to ignore the home page, or to exclude robots.txt by putting a | where query before the summarize operator

requests 
| where url != 'https://pjlee.net/' 
   and url != 'https://www.pjlee.net/'
    and url != 'http://pjlee.net/'
    and url != 'http://www.pjlee.net/'
    and not(url contains '.ico')
    and not(url contains '.js')
    and not(url contains '.css')
    and not(url contains '.txt')  
    and not(url contains '.php')  
| summarize count() by url
| order by count_

You can run this in the Application Insights logs page for your site (selecting a suitable time period), and then pin it to an Azure dashboard.

You can also get charts of counts of requests summarized for each day and include those on the same dashboard.