Forum Discussion

Sunil Bommala's avatar
Sunil Bommala
Copper Contributor
Aug 30, 2018

Perf counter

Hi,

 

How can I get Perf data for the past 24hrs for CPU, Memory, using log analytics so that I can export the data and create CPU chart outside Azure for the past 24hrs. 

7 Replies

  • Billy York's avatar
    Billy York
    Iron Contributor

    Hi Sunil, you didn't give a whole lot to go on, so I made some assumptions. This will get the % of memory in use over the last 24 hours bin by 1 hour and join it with CPU over the last 24 hours also bin by 24 hours.

    //get % of memory last 24 hours bin time generated 1 hour

    let AvgMem = Perf

    | where ObjectName == "Memory"

    and CounterName == "% Committed Bytes In Use"

    and TimeGenerated < now(24h)

    | summarize avg(CounterValue) by bin(TimeGenerated, 1h), Computer

    | project AvgMemory=avg_CounterValue, Computer, TimeGenerated;

    //end memory

    //get % of CPU used 24 hours bin time generated 1 hour

    let CPU = Perf

    | where ObjectName == "Processor"

    and InstanceName == "_Total"

    and TimeGenerated < now(24h)

    | summarize avg(CounterValue) by bin(TimeGenerated, 1h), Computer

    | project AvgCPU = avg_CounterValue, Computer, TimeGenerated;

    //end cpu

    //Join CPU query with AvgMem query on Computer name column

    CPU | join (AvgMem) on Computer

    | project Computer, AvgCPU, AvgMemory, TimeGenerated

     

    if you find you don't the counters i've used or you want to try different ones you can use the below to find out what counters you currently have in your environment.

    Perf | distinct ObjectName, CounterName

    • Patrick Naughton's avatar
      Patrick Naughton
      Brass Contributor

      A more concise way to express the same thing without needing to join.

       

      Perf
      | where (ObjectName == "Memory" and CounterName == "% Committed Bytes In Use")
      or (ObjectName == "Processor" and CounterName == "% Processor Time" and InstanceName == "_Total")
      and TimeGenerated < now(24h)
      | summarize avg(CounterValue) by bin(TimeGenerated, 1h), Computer, ObjectName
      | evaluate pivot(ObjectName, avg(avg_CounterValue))
      | project TimeGenerated, Computer, Processor, Memory

       

      • Billy York's avatar
        Billy York
        Iron Contributor

        nice, I knew there had to be a way to summarize multiple values in the same perf query, thanks! and evaluate pivot has been on my short list to understand better. Thanks for that, two birds, one stone.

    • Billy York's avatar
      Billy York
      Iron Contributor

      sorry I forgot, once you're happy with the query and the data you can export the data to CSV as shown in the screen grab. or you can connect PowerBI.

      • Sunil Bommala's avatar
        Sunil Bommala
        Copper Contributor

        Thx for reply. I am looking for help with the query itself. 

         

        let startTimestamp = ago(1d);

        Perf

        | where ContainerName == "platformservices" and CounterName == "% Processor Time"

         

         

        'where' operator: Failed to resolve column or scalar expression named 'ContainerName' Support id: 6676cddc-3db3-46ec-bab9-76aeddf5b402

Resources