[Discovery - CPU Count/Cores] Understanding how the CPU count and CPU cores for virtual boxes. (Linux/Windows)


Details

Question #1
How do we get the CPU information for the Linux Servers (Physical/Virtual servers)

Answer
Linux uses command cat /proc/cpuinfo to fetch the information in regards to the CPUs. This information also includes the "physical id" of each processor.

Reference: Please refer the pattern "Linux Server" step# 12.1 (Get CPU info)

Question #2
How do we populate the CPU Count for the Linux Servers (Physical/Virtual)?

Answer:
We calculate CPU's based on the unique Physical id. Other-words lets say we have few processors but with same physical id then we consider it as a single CPU. Based on sample data below, you can see here from the output that all processors have physical id as 0. This is counted as 1 CPU as they are all associated with the same physical id.

Sample Data:
""
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 62
model name : Intel(R) Xeon(R) CPU E7-8890 v2 @ 2.80GHz
stepping : 7
microcode : 0x715
cpu MHz : 2793.269
cache size : 38400 KB
physical id : 0

processor : 2
vendor_id : GenuineIntel
cpu family : 6
model : 62
model name : Intel(R) Xeon(R) CPU E7-8890 v2 @ 2.80GHz
stepping : 7
microcode : 0x715
cpu MHz : 2793.269
cache size : 38400 KB
physical id : 0
""

If there are processors with different physical id like 0 and 1, it will be counted as 2 CPUs.

Reference: Please refer the pattern "Linux Server" step# 12.5 (Parse CPU data)
Also refer the KB below: https://hi.service-now.com/kb_view.do?sysparm_article=KB0817725
Code:
""
if (name == "physical id")
{
physical_id_in_curr_block = value;
if (!physicalIds[value])
{
physicalIds[value] = true;
physicalIds.count++;
}
}
""


Question #3:
How do we populate the CPU count for Windows servers (physical or virtual)?

Answer:
We use the Win32_Processor API and get the information like "NumberofCores and NumberofLogicalProcessors"

Reference: Please refer the pattern "Windows OS - Server" step# 9.1.1 (Get partial CPU data from Win32_Processor)

Screen Shot 2020-06-18 at 10.56.57 AM.png


Question #4:
How do we populate the CPU count for Windows Servers (Physical or Virtual)

Answer:
We populate the count of the processor's table.

Reference: Please refer the pattern "Windows OS - Server" step# 10 (Insert System, OS and CPU data to cmdb_ci_win_server)
Code:
""
var rtrn = '';
var processorsTable = ${Win32_Processor};
rtrn = (processorsTable)?processorsTable.size():"";
""

Additional Information