I had a recent email from one of my customers. HIs organization was about ready to go through some licensing true-ups and he was in a bit of a pickle. He had a few 3rd-party products they needed to do some accounting on and each product was licensed using a different model. Sadly they did not have any type of CMDB in place to help (Configuration Management Database - something very handy to have when it comes to looking at your server inventory). I thought back to my years of running a large Enterprise *NIX team and shuddered; easily once every month or so someone came by asking me the exact same questions.
So we worked on a few simple commands that can be used to produce this data. First we tried this:
$ lscpu | grep 'socket'
Core(s) per socket: 2
CPU socket(s): 1
At this command's "core" [ha ha, pun intended] we got exactly what my pal Tom wanted, and then some. Not only can we see how many sockets he was using (which is what he was reporting for) but we also found out how many cores there were in each socket.
Next we tried something that while much less pretty, zeroed in on the exact requirement:
$ cat /proc/cpuinfo | grep "physical id" | sort -u | wc -l
This told us exactly how many sockets we had. And then for fun (Tom is nothing if not fun) we wondered how you could account for if something was hyperthreaded or not so he whipped out this:
$ egrep -e "core id" -e ^physical /proc/cpuinfo|xargs -l2 echo|sort -u
physical id : 0 core id : 0
physical id : 0 core id : 1
So Tom went back to work, happy and ready to give his bosses EXACTLY what they needed (he was so happy he had a new scripting project to tinker with). These commands worked from RHEL6 back to RHEL4 so most everyone should be able to use them, So if you're interested in giving these a whirl, there are also a few official knowledge solutions produced by our esteemed Ryan Sawhill you may want to review too:
How to determine number of CPU sockets on a system
Difference between physical cpus, cpu cores, and logical cpus
So what do you think? Is this useful stuff? Will this save you any time or even help you start off your own CMDB? We'd love to hear from you!
Technical Account Manager
Red Hat Inc.