title: Find the start and end time (or time span) of the kusto query is running on azure log analytics?
body: <p>I am struggling here to find the time interval over which the kusto query is being run.</p>
  
  <p>What I am trying to do is to calculate the downtime of some specific API's which are running on Azure app service. All the logs of the azure APP service are present in App analytics.</p>
  
  <p>To plot the downtime , I was able to find the number of minutes for the API is considered down through the query.</p>
  
  <p>Now the challenge is to calculate  the UP time percentage. The query runs over the logs selected through the time range provided on portal. </p>
  
  <p>Meaning if I change the time range in console, the downtime minutes are getting calculated accordingly. But as I don't know the time range, I am not able to calculate the % up time for the it.</p>
  
  <p>Right now,  I have to update the query every time , I change the time range from console to calculate UP time percentage.</p>
  
  <p><strong>Edit 1</strong></p>
  
  <pre><code>requests
  | where client_Type != "Browser" 
  | where operation_Name =~ 'GET Account/Login'
  | summarize failed_requests=sumif(itemCount, toint(resultCode) &gt;= 500), total_requests=sum(itemCount)  by bin(timestamp, 1m)
  | extend failure_percentage=(failed_requests * 100/ total_requests)
  | extend external_sla_failure=iff(failure_percentage &lt; 100, 0, 1) 
  | extend internal_sla_failure=iff(external_sla_failure == 0  and failed_requests &lt; 3, 0 , 1)
  | summarize internal_sla_downtime_min=sum(internal_sla_failure), external_sla_downtime_min=sum(external_sla_failure)
  </code></pre>
  
  <p>This query calculates the two downtime , internal and external. Now I just want to calculate the <strong>% uptime</strong> for both downtime. To calculate that I will need the time duration selected from the portal time range picker. </p>
  
  <p>This time range is selected from azure portal app analytics time range picker or from azure dashboard time picker. Is there any variable or something which stores the time span (or start and endtime) which has been selected from the time picker on portal (either app analytics or azure dashboard)  ?</p>
  
  <p><strong>Edit 2</strong></p>
  
  <p>I can put a hacky but imperfect logic by using <strong>min</strong> and <strong>max</strong> function on <strong><em>timestamp</em></strong> to get start and endtime but if the app does not receive any request for first <strong>n</strong> minutes or last <strong>m</strong> minutes of the selected time , the <strong>% uptime</strong> calculation will show incorrect data. </p>