Freigeben über


Azure Log Analytics: Finding CPUs with perf counters

Today I saw a question on how find the count of CPUs that a server has, maybe you need this for licensing or maybe just for inventory purposes.  I remember looking at this before…

The easiest way I’ve found (unless you know different) was to convert a syntax I used in the old query language to ALA v2.

You may need to add "Processor(*)\% Processor" to your Windows Performance Counter list in [Advanced Settings]

This counter gives you the _Total and info for each CPU.  So this line will find all Processor data:

| where ObjectName == "Processor" and CounterName == "% Processor Time"

However to exclude _Total, I added this syntax to ignorethe total info, i.e.  !=”_Total” giving me the full line:

| where ObjectName == "Processor" and CounterName == "% Processor Time" and InstanceName!="_Total"  

This can give you a report like this:

image

I liked the extra detail of showing the CPUs in a list, for this once again I used makeset and sort to get the data in order (however I need to look at a better method as above 10CPUs the order is wrong).  So I ended up with:

// needs perf counter "Processor(*)\% Processor"
Perf
| where TimeGenerated >= ago(1h)
| where ObjectName == "Processor" and CounterName == "% Processor Time" and InstanceName!="_Total"
| sort by InstanceName asc nulls first
| summarize makeset(InstanceName), dcount(InstanceName) by Computer

image