Say you had a lot of standalone ESX servers, at well known ip addresses, and needed to find out how many cpu sockets or physical packages are in use… because you are migrating to Virtual Center.
This info can be found in /proc/vmware/sched/ncpus
Here is a sample script to do the count :
#!/bin/sh
#
# get-vmware-cpu-sockets.sh
SSH_KEY=/path/to/id_dsa
SSH="ssh -n -T -i ${SSH_KEY} -o strictHostKeyChecking=no"
echo "Server,Sockets"
total=0
server=1
while [ $server -le 250 ]
do
# all our esx servers are at 10.252.x.1
ip=10.252.${server}.1
ping -c 3 ${ip} >/dev/null 2>&1 && {
# if it reports socket or package, use that.
# these servers may also report physical as in 2 or 4 physical per socket
# but we are only interested in the socket number
sockets=`${SSH} root@${ip} “cat /proc/vmware/sched/ncpus” 2>/dev/null |\
egrep -i ’socket|package’ |\
awk ‘{print $1}’`
# some machines report only physical tag, but not socket/package
if [ -z “${sockets}” ] ; then
sockets=`${SSH} root@${ip} “cat /proc/vmware/sched/ncpus” 2>/dev/null |\
grep -i physical | awk ‘{print $1}’`
fi
if [ ! -z “${sockets}” ] ; then
total=`expr ${total} + ${sockets}`
echo “${ip},${sockets}”
fi
}
server=`expr ${server} + 1`
done
echo
echo “Total,${total}”
echo
Yes, I use expr and other techniques that tell you I started shell scripting before BASH ever existed…
$ ./get-vmware-cpu-sockets.sh
Server,Sockets
10.252.3.1,4
10.252.4.1,2
10.252.8.1,2
10.252.16.1,2
10.252.17.1,2
10.252.19.1,2
10.252.20.1,2
10.252.22.1,2
10.252.23.1,2
10.252.24.1,2
10.252.25.1,2
10.252.26.1,4
10.252.29.1,2
10.252.30.1,4
10.252.31.1,4
10.252.32.1,2
10.252.33.1,2
10.252.34.1,2
10.252.37.1,2
10.252.38.1,4
10.252.40.1,4
10.252.41.1,4
10.252.42.1,4
10.252.43.1,8
10.252.44.1,8
10.252.45.1,8
Total,86
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=15df9461-727a-4447-a904-a1c81e5dc5fb)
Leave a Reply