Aug 30 2018
10:18 AM
- last edited on
Apr 07 2022
05:27 PM
by
TechCommunityAP
Aug 30 2018
10:18 AM
- last edited on
Apr 07 2022
05:27 PM
by
TechCommunityAP
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.
Aug 30 2018 12:28 PM - edited Aug 30 2018 12:37 PM
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
Aug 30 2018 12:35 PM
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.
Aug 30 2018 01:08 PM
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
Aug 30 2018 01:22 PM
It looks like it can’t find the field “ContainerName” Make sure the case is correct and ContainerName is part of the Perf Schema.
Aug 31 2018 12:35 AM
Hi There,
You can only get below things in Perf query as per schema of this query synatx. I am not sure if you can get any custom thing apart from this.
TenantId
Computer
ObjectName
CounterName
InstanceName
CounterValue
TimeGenerated [Central Time (US and Canada)]
SourceSystem
Aug 31 2018 05:49 PM
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
Aug 31 2018 09:31 PM
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.