Forum Discussion

DurgaPrasad635's avatar
DurgaPrasad635
Copper Contributor
Jul 11, 2022

Need help with log analytics query for API failure percentage

Hi,

 

I am trying to get API management service failure percentage in Log analytics, but not getting anywhere. Can anyone please help in this ?

 

something like below I tried but no luck, still learning

let totalreq = AppRequests
| count
| project Count;

AppRequests
| where Success == false
| project OperationName, failure_percentage = counto / totalreq * 100

 

 

 

  • Clive_Watson's avatar
    Clive_Watson
    Jul 12, 2022

    DurgaPrasad635 

     

    Yes, just add this.  I did add a filter so only entries above 1% are shown (in the test data I get a lot below that...you may want all of them or another number)

    let totalreq = toscalar(AppRequests
    | count);
    AppRequests
    | summarize failure_percentage =countif(Success=='False') / todouble(totalreq) * 100  by OperationName
    | where failure_percentage > 1
    | render barchart 

     

    Go to Log Analytics and run query

  • Clive_Watson's avatar
    Clive_Watson
    Bronze Contributor

    You can try this, the trick is to use the toscalar() function: toscalar() - Azure Data Explorer | Microsoft Docs

    let totalreq = toscalar(AppRequests
    | count);
    AppRequests
    | summarize failure_percentage =countif(Success=='False') / todouble(totalreq) * 100 , success_percentage =countif(Success=='True')  / todouble(totalreq) * 100

     I did success and failure, just to make sure they added up to 100% - remove the success part if not needed  

    • DurgaPrasad635's avatar
      DurgaPrasad635
      Copper Contributor

      Clive_Watson 

       

      Thanks this helped me!

       

      Is it possible to get OperatonName which is failed ? just tryint to create a dashboard.

       

      Thanks

      • Clive_Watson's avatar
        Clive_Watson
        Bronze Contributor

        DurgaPrasad635 

         

        Yes, just add this.  I did add a filter so only entries above 1% are shown (in the test data I get a lot below that...you may want all of them or another number)

        let totalreq = toscalar(AppRequests
        | count);
        AppRequests
        | summarize failure_percentage =countif(Success=='False') / todouble(totalreq) * 100  by OperationName
        | where failure_percentage > 1
        | render barchart 

         

        Go to Log Analytics and run query

Resources